repat/respond-io-client

Client for respond.io contacts and messaging API

dev-main 2022-08-30 10:35 UTC

This package is auto-updated.

Last update: 2024-03-29 04:40:09 UTC


README

⚠️ WORK IN PROGRESS ⚠️

respond-io-client is the unofficial package for the respond.io messaging platform API. Pull requests welcome.

Installation

composer require repat/respond-io-client

Usage

The library will generally throw Guzzle's Exceptions, see Contacts API Error Codes and Messages API Error Codes in their documentation.

Setup

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

Contacts

Please note that in case of Viber Channel - due to a certain limitation - the Contact ID needs to be provided in a Base64 encoded format.

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

/*
|--------------------------------------------------------------------------
| Get Contacts
|--------------------------------------------------------------------------
*/
// If you know the ID
$client->getContactById($id);

// Search by field
$customFieldName = 'phone';
$customFieldValue = '+15551234567';
$client->getContactByCustomField($customFieldName, $customFieldValue);

/*
|--------------------------------------------------------------------------
| Update Contacts
|--------------------------------------------------------------------------
*/
$fields = [
	'phone' => '+15557654321',
];

$client->updateContact($id, $fields);

/*
|--------------------------------------------------------------------------
| Tags
|--------------------------------------------------------------------------
*/

$tags = ['foo', 'bar'];

$client->addTag($id, $tags);
$client->removeTag($id, $tags);

/*
|--------------------------------------------------------------------------
| Create Contact
|--------------------------------------------------------------------------
*/
$fields = [
	'firstName' => 'John',
	'lastName' => 'Doe',
	'phone' => '+15551234567',
	'email' => 'test@example.com'
	//
];

$client->createContact($fields);

Messages

/*
|--------------------------------------------------------------------------
| Text
|--------------------------------------------------------------------------
*/

$client->sendText($id, $text);

/*
|--------------------------------------------------------------------------
| Attachments
|--------------------------------------------------------------------------
*/
$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);

/*
|--------------------------------------------------------------------------
| Quick Reply
|--------------------------------------------------------------------------
*/

$title = 'Would you like Foo, Bar or Baz?';
$replies = ['Foo', 'Bar', 'Baz'];

$client->sendQuickReply($id, $title, $replies);

ToDo

License

  • MIT

Version

  • Version 0.1

Contact

repat

Flattr this git repo