-
Notifications
You must be signed in to change notification settings - Fork 96
ChatAPI functionality #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
3d878e5
d01f7a2
feb2fe5
4c7d2af
5f35d27
f6ee6b8
5846687
bd6ce36
52cc8b8
ef3816f
3421376
672a188
445f58c
8e68414
c862e28
cb51812
e98e014
b599d14
3516285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
|
||
$ChatChannel = new \MessageBird\Objects\Chat\Channel(); | ||
|
||
//Example for telegram channel | ||
|
||
$ChatChannel->name = 'Test Channel Telegram'; | ||
$ChatChannel->platform_id = 'e82d332c5649a5f911e569n69040697'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
|
||
// Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) | ||
// are required when creating a channel for this platform. | ||
|
||
$ChatChannel->channelDetails = | ||
array( | ||
'botName' => 'testBot', | ||
'token' => '1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA' | ||
); | ||
|
||
try { | ||
$ChatChannelResult = $MessageBird->chatchannels->create($ChatChannel); | ||
var_dump($ChatChannelResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
try { | ||
|
||
$deleted = $MessageBird->chatchannels->delete('4affac2c577fb22e373921n52675409'); // Set a message id here | ||
var_dump('Deleted: ' . $deleted); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
try { | ||
$ChatChannelResult = $MessageBird->chatchannels->getList(); | ||
var_dump($ChatChannelResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
$ChatChannel = new \MessageBird\Objects\Chat\Channel(); | ||
$ChatChannel->name = 'New name'; | ||
$ChatChannel->callbackUrl = 'http://newurl.dev'; | ||
|
||
|
||
try { | ||
|
||
$ChatChannelResult = $MessageBird->chatchannels->update($ChatChannel, '331af4c577e3asbbc3631455680736'); | ||
var_dump($ChatChannelResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
try { | ||
$ChatChannelResult = $MessageBird->chatchannels->read('0051af4c577e3eebbc3631n95680736'); // Set a channel id here | ||
var_dump($ChatChannelResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. | ||
|
||
try { | ||
|
||
$deleted = $MessageBird->chatcontacts->delete('4affa2345d7fb22e373921n524df5409'); // Set a message id here | ||
var_dump('Deleted : ' . $deleted); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
try { | ||
|
||
$ChatContactResult = $MessageBird->chatcontacts->getList(); | ||
var_dump($ChatContactResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
try { | ||
|
||
$ChatContactResult = $MessageBird->chatcontacts->read('0051af4c577e3eebbc3631n95680736'); // Set a contact id here | ||
var_dump($ChatContactResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
$ChatMessage = new \MessageBird\Objects\Chat\Message(); | ||
$ChatMessage->contactId = '9d754dac577e3ff103cdf4n29856560'; | ||
$ChatMessage->payload = 'This is a test message to test the Chat API'; | ||
$ChatMessage->type = 'text'; | ||
|
||
|
||
try { | ||
$ChatMessageResult = $MessageBird->chatmessages->create($ChatMessage); | ||
var_dump($ChatMessageResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\MessageBird\Exceptions\BalanceException $e) { | ||
// That means that you are out of credits, so do something about it. | ||
echo 'no balance'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
|
||
$ChatMessage = new \MessageBird\Objects\Chat\Message(); | ||
|
||
|
||
try { | ||
$ChatMessageResult = $MessageBird->chatmessages->getList(); | ||
var_dump($ChatMessageResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
$ChatMessage = new \MessageBird\Objects\Chat\Message(); | ||
|
||
try { | ||
|
||
$MessageResult = $MessageBird->chatmessages->read('d6508edc578ca7641e3919n79796670'); // Set a message id here | ||
var_dump($MessageResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
require_once(__DIR__ . '/../autoload.php'); | ||
|
||
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummy access key contains tab character. |
||
|
||
$ChatPlatform = new \MessageBird\Objects\Chat\Channel(); | ||
|
||
try { | ||
|
||
$ChatPlatformResult = $MessageBird->chatplatforms->getList(); | ||
var_dump($ChatPlatformResult); | ||
|
||
} catch (\MessageBird\Exceptions\AuthenticateException $e) { | ||
// That means that your accessKey is unknown | ||
echo 'wrong login'; | ||
|
||
} catch (\Exception $e) { | ||
echo $e->getMessage(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ class Client | |
{ | ||
|
||
const ENDPOINT = 'https://rest.messagebird.com'; | ||
const CHATAPI_ENDPOINT = 'https://chat.messagebird.com/1'; | ||
|
||
const CLIENT_VERSION = '1.4.1'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be updated during release somehow? |
||
|
||
|
@@ -59,20 +60,31 @@ class Client | |
*/ | ||
protected $HttpClient; | ||
|
||
/** | ||
* @var Common\HttpClient | ||
*/ | ||
protected $ChatAPIHttpClient; | ||
|
||
/** | ||
* @param string $accessKey | ||
* @param Common\HttpClient $httpClient | ||
*/ | ||
public function __construct($accessKey = null, Common\HttpClient $httpClient = null) | ||
{ | ||
if ($httpClient == null) { | ||
$this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); | ||
$this->HttpClient = new Common\HttpClient(self::ENDPOINT); | ||
} else { | ||
$this->ChatAPIHttpClient = $httpClient; | ||
$this->HttpClient = $httpClient; | ||
} | ||
|
||
$this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); | ||
$this->HttpClient->addUserAgentString($this->getPhpVersion()); | ||
|
||
$this->ChatAPIHttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); | ||
$this->ChatAPIHttpClient->addUserAgentString($this->getPhpVersion()); | ||
|
||
if ($accessKey !== null) { | ||
$this->setAccessKey($accessKey); | ||
} | ||
|
@@ -84,6 +96,11 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n | |
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient); | ||
$this->lookup = new Resources\Lookup($this->HttpClient); | ||
$this->lookupHlr = new Resources\LookupHlr($this->HttpClient); | ||
$this->chatmessages = new Resources\Chat\Message($this->ChatAPIHttpClient); | ||
$this->chatchannels = new Resources\Chat\Channel($this->ChatAPIHttpClient); | ||
$this->chatplatforms = new Resources\Chat\Platform($this->ChatAPIHttpClient); | ||
$this->chatcontacts = new Resources\Chat\Contact($this->ChatAPIHttpClient); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -92,6 +109,8 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n | |
public function setAccessKey ($accessKey) | ||
{ | ||
$Authentication = new Common\Authentication($accessKey); | ||
|
||
$this->ChatAPIHttpClient->setAuthentication($Authentication); | ||
$this->HttpClient->setAuthentication($Authentication); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dummy access key contains tab character.