dbatten5/textline-php

There is no license information available for the latest version (1.0) of this package.

PHP client for the Textline API

1.0 2019-03-02 13:26 UTC

This package is auto-updated.

Last update: 2024-04-05 17:56:48 UTC


README

Setup

Using composer:

composer require dbatten5/textline-php

Usage

Authentication

When initializing the client you must provide your api key (obtained here) and email and password of the agent you want represented by your API requests. This will make a request to the Textline API to retrieve an authentication token which will then automatically be attached to all subsequent requests to the api. If you already know your token you may pass it in as the fourth argument.

<?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);

If the api key and/or token are incorrect a Textline\Exceptions\AuthenticationException will be thrown.

Conversations

List conversations

$client->conversations()
       ->get();

To add query parameters listed here pass in an array of key values:

$query = [
    'page' => 1,
    'page_size' => 20,
    'query' => 'foo',
];

$client->conversations()
       ->get($query);

Message a phone number

$number = '0781234567';
$body = [
    'comment' => [
        'body' => 'foo'
    ]
];

$client->conversations()
       ->messageByPhone($number, $body);

For a list of a $body options see here. Note that either whisper or comment must be specified in the request, but not both.

Schedule a message by phone number

$number = '07812345678';
$timestamp = 1551528788; # unix timestamp
$body = 'foo';
$params = [
    'group_uuid' => '123' # optional extra params
];

$client->conversations()
       ->scheduleByPhone($number, $timestamp, $body, $params);

Conversation

Retrieve a conversation

$uuid = 'abc-123';

$client->conversation($uuid)
       ->retrieve();

To add query parameters listed here pass in an array of key values as the second argument.

Message a conversation

Pass in the conversation uuid as the first argument and the message attributes as the second argument:

$uuid = 'abc-123';
$body = [
    'comment' => [
        'body' => 'foo',
    ],
    'whisper' => [
        'body' => 'bar',
    ]
];

$client->conversation($uuid)
       ->message($body);

Schedule a message to a conversation

$uuid = 'abc-123';
$timestamp = 1551528788; # unix timestamp
$body = 'foo';

$client->conversation($uuid)
       ->scheduleMessage($timestamp, $body);

Resolve a conversation

$uuid = 'abd-123';

$client->conversation($uuid)
       ->resolve();

Transfer a conversation

$uuid = 'abd-123';

$client->conversation($uuid)
       ->transfer();

Customers

List customers

$client->customers()
       ->get();

To add query parameters listed here pass in an array of key values:

$query = [
    'page' => 1,
    'page_size' => 20,
    'query' => 'foo',
];

$client->customers()
       ->get($query);

Create a customer

$number = '07812345678';
$attrs = [
    'email' => 'john@mail.com',
    'name' => 'John Mail',
];

$client->customers()
       ->create($number, $attrs);

For a full list of attributes see here

Customer

Retrieve a customer

$uuid = 'abc-123';

$client->customer($uuid)
       ->retrieve();

Update a customer

$uuid = 'abc-123';
$attrs = [
    'name' => 'John Smith',
    'email' => 'john@smith.com',
];

$client->customer($uuid)
       ->update($attrs);

Organization

Retrieve organization details

$query = [
    'include_groups' => false,
];

$client->orgnization()
       ->get($query);

For a full list of available query options see here

Exceptions

  • If a conversation, customer or other resource identified with a uuid is not found, a Textline\Exceptions\ResourceNotFoundException will be thrown

  • If the rate limit is exceeded a Textline\Exceptions\RateLimitException will be thrown

  • For all other client errors, a generic Textline\Exceptions\ClientException will be thrown