dbatten5 / textline-php
该软件包最新版本(1.0)的许可证信息不可用。
Textline API 的 PHP 客户端
1.0
2019-03-02 13:26 UTC
Requires
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- mockery/mockery: dev-master
- php-vcr/php-vcr: ^1.4
- php-vcr/phpunit-testlistener-vcr: ^3.2
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-05 18:49:08 UTC
README
设置
使用 composer
composer require dbatten5/textline-php
用法
认证
在初始化客户端时,您必须提供您的 API 密钥(在此 获取)以及您希望由您的 API 请求代表的代理的电子邮件和密码。这将向 Textline API 发送请求以检索一个认证令牌,该令牌将自动附加到所有后续的 API 请求。如果您已经知道您的令牌,您可以将它作为第四个参数传递。
<?php $apiKey = "ZZZZZZZZ"; // Your account api key $email = "agent@acme.com"; // Email address of the agent $password = "XXXXXX"; // Password associated with the email address above $token = 'YYYYYYYY'; // Can be left null $client = new Textline\Client($email, $password, $apiKey, $token);
如果 API 密钥和/或令牌不正确,将抛出 Textline\Exceptions\AuthenticationException。
对话
列出对话
$client->conversations() ->get();
要添加查询参数,请参阅 此处 的列表,传入键值对的数组
$query = [ 'page' => 1, 'page_size' => 20, 'query' => 'foo', ]; $client->conversations() ->get($query);
给电话号码发信息
$number = '0781234567'; $body = [ 'comment' => [ 'body' => 'foo' ] ]; $client->conversations() ->messageByPhone($number, $body);
有关 $body 选项的列表,请参阅 此处。注意,请求中必须指定 whisper 或 comment 之一,但不能同时指定两者。
通过电话号码安排信息
$number = '07812345678'; $timestamp = 1551528788; # unix timestamp $body = 'foo'; $params = [ 'group_uuid' => '123' # optional extra params ]; $client->conversations() ->scheduleByPhone($number, $timestamp, $body, $params);
对话
检索对话
$uuid = 'abc-123'; $client->conversation($uuid) ->retrieve();
要添加查询参数,请参阅 此处 的列表,将键值对的数组作为第二个参数传入。
向对话发信息
将对话 uuid 作为第一个参数传入,将消息属性作为第二个参数传入
$uuid = 'abc-123'; $body = [ 'comment' => [ 'body' => 'foo', ], 'whisper' => [ 'body' => 'bar', ] ]; $client->conversation($uuid) ->message($body);
向对话安排信息
$uuid = 'abc-123'; $timestamp = 1551528788; # unix timestamp $body = 'foo'; $client->conversation($uuid) ->scheduleMessage($timestamp, $body);
解决对话
$uuid = 'abd-123'; $client->conversation($uuid) ->resolve();
转移对话
$uuid = 'abd-123'; $client->conversation($uuid) ->transfer();
客户
列出客户
$client->customers() ->get();
要添加查询参数,请参阅 此处 的列表,传入键值对的数组
$query = [ 'page' => 1, 'page_size' => 20, 'query' => 'foo', ]; $client->customers() ->get($query);
创建客户
$number = '07812345678'; $attrs = [ 'email' => 'john@mail.com', 'name' => 'John Mail', ]; $client->customers() ->create($number, $attrs);
有关属性列表的完整信息,请参阅 此处
客户
检索客户
$uuid = 'abc-123'; $client->customer($uuid) ->retrieve();
更新客户
$uuid = 'abc-123'; $attrs = [ 'name' => 'John Smith', 'email' => 'john@smith.com', ]; $client->customer($uuid) ->update($attrs);
组织
检索组织详细信息
$query = [ 'include_groups' => false, ]; $client->orgnization() ->get($query);
有关可用查询选项的完整列表,请参阅 此处
异常
-
如果找不到标识为
uuid的对话、客户或其他资源,将抛出Textline\Exceptions\ResourceNotFoundException -
如果超出配额限制,将抛出
Textline\Exceptions\RateLimitException -
对于所有其他客户端错误,将抛出通用的
Textline\Exceptions\ClientException