-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from rjelierse/restore-conversations-api
Converstations API 🚀
- Loading branch information
Showing
31 changed files
with
1,936 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
// Initiates a conversation by sending a first message. This example uses a | ||
// plain text message, but other types are also available. See the | ||
// conversations-messages-create examples. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
$content = new \MessageBird\Objects\Conversation\Content(); | ||
$content->text = 'Hello world'; | ||
|
||
$message = new \MessageBird\Objects\Conversation\Message(); | ||
$message->channelId = 'CHANNEL_ID'; | ||
$message->content = $content; | ||
$message->to = 'RECIPIENT'; // Channel-specific, e.g. MSISDN for SMS. | ||
$message->type = 'text'; | ||
|
||
try { | ||
$conversation = $messageBird->conversations->create($message); | ||
|
||
var_dump($conversation); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
// Retrieves all conversations for this account. Pagination is supported | ||
// through the optional 'limit' and 'offset' parameters. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
// Take 10 objects, but skip the first 5. | ||
$optionalParameters = array( | ||
'limit' => '10', | ||
'offset' => '5', | ||
); | ||
|
||
try { | ||
$conversations = $messageBird->conversations->getList($optionalParameters); | ||
|
||
var_dump($conversations); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
// Sends a message to an existing conversation, with a location as its content. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
$content = new \MessageBird\Objects\Conversation\Content(); | ||
$content->location = array( | ||
'latitude' => 52.379112, | ||
'longitude' => 4.900384, | ||
); | ||
|
||
$message = new \MessageBird\Objects\Conversation\Message(); | ||
$message->channelId = 'CHANNEL_ID'; | ||
$message->content = $content; | ||
$message->to = 'RECIPIENT'; | ||
$message->type = \MessageBird\Objects\Conversation\Content::TYPE_LOCATION; // 'location' | ||
|
||
try { | ||
$conversation = $messageBird->conversationMessages->create( | ||
'CONVERSATION_ID', | ||
$message | ||
); | ||
|
||
var_dump($conversation); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
// Sends a message to an existing conversation, with media as its content. | ||
// Supported media types are 'audio', 'file', 'image' and 'video. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
$content = new \MessageBird\Objects\Conversation\Content(); | ||
$content->image = array( | ||
'url' => 'https://cdn-gc.messagebird.com/assets/images/logo.png' | ||
); | ||
|
||
$message = new \MessageBird\Objects\Conversation\Message(); | ||
$message->channelId = 'CHANNEL_ID'; | ||
$message->content = $content; | ||
$message->to = 'RECIPIENT_MSISDN'; | ||
$message->type = \MessageBird\Objects\Conversation\Content::TYPE_IMAGE; // 'image' | ||
|
||
try { | ||
// Using a contactId instead of a conversationId is also supported. | ||
$conversation = $messageBird->conversationMessages->create( | ||
'CONVERSATION_ID', | ||
$message | ||
); | ||
|
||
var_dump($conversation); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
// Sends a plain text message to a contact. If there's an active conversation | ||
// with that contact the message will be added to this conversation, otherwise | ||
// it creates a new conversation. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
$content = new \MessageBird\Objects\Conversation\Content(); | ||
$content->text = 'Hello world'; | ||
|
||
$message = new \MessageBird\Objects\Conversation\Message(); | ||
$message->channelId = 'CHANNEL_ID'; | ||
$message->content = $content; | ||
$message->to = 'RECIPIENT'; | ||
$message->type = \MessageBird\Objects\Conversation\Content::TYPE_TEXT; | ||
|
||
try { | ||
$conversation = $messageBird->conversationMessages->create( | ||
'CONVERSATION_ID', | ||
$message | ||
); | ||
|
||
var_dump($conversation); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
// Retrieves all messages from the conversation. Pagination is supported | ||
// through the optional 'limit' and 'offset' parameters. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$messages = $messageBird->conversationMessages->getList('CONVERSATION_ID'); | ||
|
||
var_dump($messages); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
// Retrieves a single conversation by its ID. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
// Setting the optional 'include' parameter to 'content' requests the API to | ||
// include the expanded Contact object in its response. Excluded by default. | ||
$optionalParameters = array( | ||
'include' => 'content', | ||
); | ||
|
||
try { | ||
$conversation = $messageBird->conversations->read( | ||
'CONVERSATION_ID', | ||
$optionalParameters | ||
); | ||
|
||
var_dump($conversation); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
// Updating the conversation allows moving them between 'active' and 'archived' | ||
// status. This example restores an archived conversation by setting it to active. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$conversationId = 'CONVERSATION_ID'; | ||
$conversation = $messageBird->conversations->read($conversationId); | ||
|
||
$conversation->status = \MessageBird\Objects\Conversation\Conversation::STATUS_ACTIVE; | ||
$messageBird->conversations->update($conversation, $conversationId); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
// Webhooks enable real-time notifications of conversation events to be | ||
// delivered to endpoints on your own server. This example creates a webhook | ||
// that is invoked when new conversations and messages are created in the | ||
// specified channel. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$webhook = new \MessageBird\Objects\Conversation\Webhook(); | ||
$webhook->channelId = 'CHANNEL_ID'; | ||
$webhook->url = 'https://example.com/webhook'; | ||
$webhook->events = array( | ||
\MessageBird\Objects\Conversation\Webhook::EVENT_CONVERSATION_CREATED, | ||
\MessageBird\Objects\Conversation\Webhook::EVENT_MESSAGE_CREATED, | ||
|
||
// Other options: | ||
// \MessageBird\Objects\Conversation\Webhook::EVENT_CONVERSATION_UPDATED, | ||
// \MessageBird\Objects\Conversation\Webhook::EVENT_MESSAGE_UPDATED, | ||
); | ||
|
||
$messageBird->conversationWebhooks->create($webhook); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
// Webhooks enable real-time notifications of conversation events to be | ||
// delivered to endpoints on your own server. This example deletes an existing | ||
// webhook. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$messageBird->conversationWebhooks->delete('WEBHOOK_ID'); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
// Retrieves all webhooks this key has access to. Pagination is supported | ||
// through the optional 'limit' and 'offset' parameters. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$webhooks = $messageBird->conversationWebhooks->getList(); | ||
|
||
var_dump($webhooks); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
// Webhooks enable real-time notifications of conversation events to be | ||
// delivered to endpoints on your own server. This example retrieves an | ||
// existing webhook. | ||
|
||
require(__DIR__ . '/../../autoload.php'); | ||
|
||
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
$webhook = $messageBird->conversationWebhooks->read('WEBHOOK_ID'); | ||
|
||
var_dump($webhook); | ||
} catch (\Exception $e) { | ||
echo sprintf("%s: %s", get_class($e), $e->getMessage()); | ||
} |
Oops, something went wrong.