Skip to content

Commit

Permalink
Merge pull request #14 from dcowan-london/feat-13-telnyx-messaging-ad…
Browse files Browse the repository at this point in the history
…apter

Implement Telnyx SMS adapter
  • Loading branch information
abnegate authored Feb 8, 2023
2 parents a75d66d + 05c0f0d commit 5fdf678
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Utopia/Messaging/Adapters/SMS/Telnyx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Utopia\Messaging\Adapters\SMS;

use Utopia\Messaging\Adapters\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS;

class Telnyx extends SMSAdapter
{
/**
* @param string $apiKey Telnyx APIv2 Key
*/
public function __construct(
private string $apiKey,
) {
}

public function getName(): string
{
return 'Telnyx';
}

public function getMaxMessagesPerRequest(): int
{
return 1;
}

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(SMS $message): string
{
return $this->request(
method: 'POST',
url: 'https://api.telnyx.com/v2/messages',
headers: [
'Authorization: Bearer '.$this->apiKey,
'Content-Type: application/json',
],
body: \json_encode([
'text' => $message->getContent(),
'from' => $message->getFrom(),
'to' => $message->getTo()[0],
]),
);
}
}

0 comments on commit 5fdf678

Please sign in to comment.