-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathSMSApi.php
More file actions
51 lines (45 loc) · 1.24 KB
/
SMSApi.php
File metadata and controls
51 lines (45 loc) · 1.24 KB
1
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
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Utopia\Messaging\Adapters\SMS;
use Utopia\Messaging\Adapters\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS;
// Reference Material
// https://www.smsapi.com/docs/#2-single-sms
class SMSApi extends SMSAdapter
{
/**
* @param string $apiToken SMSApi token
*/
public function __construct(
private string $apiToken
) {
}
public function getName(): string
{
return 'SMSApi';
}
public function getMaxMessagesPerRequest(): int
{
return 1000;
}
/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: 'https://api.smsapi.com/sms.do',
headers: [
'Authorization: Bearer '.$this->apiToken,
'content-type: application/json',
],
body: \json_encode([
'from' => $message->getFrom(), //sendername made in https://ssl.smsapi.com/sms_settings/sendernames
'to' => $message->getTo()[0], //destination number
'message' => $message->getContent(), //message content
]),
);
}
}