repat/respond-io-client

respond.io 联系人和消息API客户端

1.0 2024-05-28 19:03 UTC

This package is auto-updated.

Last update: 2024-08-28 19:30:21 UTC


README

⚠️ 进行中 ⚠️

respond-io-client 是 respond.io 消息平台 API 的非官方包。版本 0.1 支持API V1,而版本 1.0 现在也支持 V2。

欢迎提交拉取请求。

安装

composer require repat/respond-io-client

使用

该库通常抛出Guzzle的异常,请参阅 respond.io API错误代码(在 respond.io 文档中)。

设置

$apiToken = '...'; // Get an API token from the website, one per channel
$options = []; // Guzzle Options - should probably be left empty, but just in case.
// ...
$client = new \Repat\RespondIoClient\Client($apiToken, $options);

联系人

请注意,对于Viber渠道,由于某些限制,联系人ID需要以Base64编码的格式提供。

// Get ID
$id = '...';

// Set identifying field to use for searches, creation and updates
$identifyingField = 'phone';
获取联系人

'获取联系人' respond.io 文档

// If you know the ID
$client->getContactById($id);
搜索联系人

'列出联系人' respond.io 文档

  • $cursorId:搜索的起始位置,默认为null。respond.io的响应将包含一个新的cursorId,可以用于后续调用。(整数)
  • $limit:要返回的记录数。最大为100。(整数)
$filter = new ContactFilter();
$filter->addFilter(
	field: 'phone',
	operator: 'isEqualTo',
	value: '+15551234567'
)
$client->getContacts($filter, $cursorId, $limit);
更新联系人
  • $identifyingField:必须在fields数组中作为键存在
$fields = [
	'phone' => '+15557654321',
];

$client->updateContact($fields, $identifyingField);
标签
$tags = ['foo', 'bar'];

$client->addTag($id, $tags);
$client->removeTag($id, $tags);
创建联系人
  • $identifyingField:必须在fields数组中作为键存在
$fields = [
	'firstName' => 'John',
	'lastName' => 'Doe',
	'phone' => '+15551234567',
	'email' => 'test@example.com'
	//
];

$client->createContact($fields, $identifyingField);

消息

发送消息
$client->sendMessage($id, $text);
发送附件
$type = Client::TYPE_IMAGE; // 'image'

// OR:
// $type = Client::TYPE_AUDIO; // 'audio'
// $type = Client::TYPE_VIDEO; // 'video'
// $type = Client::TYPE_FILE; // 'file

$url = 'https://repat.de/Bilder/repat40x40.png';

$client->sendAttachment($id, $type, $url);

待办事项

许可协议

  • MIT

版本

  • API v1:版本 0.1(初始版本,进行中)
  • API v2:版本 1.0(社区维护)

联系

repat(v1作者)

repat(v2作者)

Flattr this git repo