Contributte Gosms
# GoSMS.cz (opens new window) Api Integration
# Content
# Requirements
Create account on GoSMS.cz (opens new window) and copy clientId and clientSecret from administration.
If you use default HTTP client, you need to install and register guzzlette (opens new window) extension.
GoSMS.cz (opens new window) access tokens are valid for 3600 seconds. Default AccessTokenCacheProvider
stores them in cache using nette/caching (opens new window);
- clientId
- clientSecret
- httpClient
- accessTokenProvider
# Installation
extensions:
guzzlette: Contributte\Guzzlette\DI\GuzzleExtension # optional for default HTTP client
gosms: Contributte\Gosms\DI\GoSmsExtension
gosms:
# Required
clientId: 10185_2jz2pog5jtgkocs0oc0008kow8kkwsccsk8c8ogogggs44cskg
clientSecret: caajrzi80zs4cwgg8400swwo8wgc4kook0s8s48kw8s00sgws
# Optional
httpClient: Contributte\Gosms\Http\GuzzletteClient
accessTokenProvider: Contributte\Gosms\Auth\AccessTokenCacheProvider
2
3
4
5
6
7
8
9
10
11
12
# Usage
We prepared 2 clients: AccountClient
and MessageClient
. They mirror methods from GoSMS.cz Api documentation (opens new window) so read documentation first. All methods except send
return raw data as received from GoSMS.cz (opens new window) api.
All methods throw ClientException with error message and code as response status when response status is not 200/201;
# AccountClient
detail()
- Organization detail (opens new window)
# MessageClient
send(Contributte\Gosms\Entity\Message)
- Sends message (opens new window)- Unfortunately GoSMS.cz (opens new window) does not include newly created message ID. We parse their response for you and include it in result object as
parsedId
. This id is needed by other methods.
- Unfortunately GoSMS.cz (opens new window) does not include newly created message ID. We parse their response for you and include it in result object as
test(Contributte\Gosms\Entity\Message)
- Test creating message withou sending (opens new window)detail(string $id)
- Sent message detail (opens new window)replies(string $id)
- List sent message replies (opens new window)delete(string $id)
- Delete sent message (opens new window)
<?php
namespace App;
use Contributte\Gosms\Client\MessageClient;
use Contributte\Gosms\Entity\Message;
use Contributte\Gosms\Exception\ClientException;
final class SendPaymentsControl extends BaseControl
{
/** @var MessageClient */
private $messageClient;
public function __construct(MessageClient $messageClient)
{
$this->messageClient = $messageClient;
}
public function handleSend(): void
{
$result = NULL;
$msg = new Message('Message body', ['+420711555444'], 1);
try {
$result = $this->messageClient->send($msg);
} catch (ClientException $e) {
// Response status
$e->getCode();
// Response body
$e->getMessage();
exit;
}
// Process successful result as you like
$this->saveSentMessage($result->parsedId, $msg);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# AccessTokenProvider
We have two build in AccessToken providers;
AccessTokenClient
- fetches and stores accessToken for 1 requestAccessTokenCacheProvider
- fetches and stores accessToken in cache until access token expires