From 02b2bf46febbcca51d6e42d9d212c2cadf5c5c82 Mon Sep 17 00:00:00 2001 From: HarshitVashisht11 Date: Tue, 10 Oct 2023 18:48:17 +0530 Subject: [PATCH 1/3] Initial commit --- src/Utopia/Messaging/Adapters/SMS/Gupshup.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/Gupshup.php diff --git a/src/Utopia/Messaging/Adapters/SMS/Gupshup.php b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php new file mode 100644 index 00000000..5b0804f2 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php @@ -0,0 +1,57 @@ +apiKey = $apiKey; + } + + public function getName(): string + { + return 'Gupshup'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1; + } + + /** + * {@inheritdoc} + * + * @throws \Exception + */ + protected function process(SMS $message): string + { + $url = 'https://api.gupshup.io/sm/api/v1/msg'; + + $headers = [ + 'Authorization: Bearer ' . $this->apiKey, + 'Content-Type: application/json', + ]; + + $data = [ + 'channel' => 'sms', + 'src' => $message->getFrom(), + 'dst' => $message->getTo()[0], + 'text' => $message->getContent(), + ]; + + return $this->request( + method: 'POST', + url: $url, + headers: $headers, + body: json_encode($data), + ); + } +} From 2675415193cfe903370917f7634979da060a12c3 Mon Sep 17 00:00:00 2001 From: HarshitVashisht11 Date: Fri, 13 Oct 2023 17:15:47 +0530 Subject: [PATCH 2/3] Initial commit --- .github/workflows/tests.yml | 4 +++ docker-compose.yml | 3 ++ src/Utopia/Messaging/Adapters/SMS/Gupshup.php | 7 +++-- tests/e2e/SMS/GupshupTest.php | 31 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/SMS/GupshupTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..24dd26fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,6 +40,10 @@ jobs: VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} VONAGE_TO: ${{ secrets.VONAGE_TO }} VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + GUPSHUP_API_KEY: ${{ secrets.GUPSHUP_API_KEY }} + GUPSHUP_TO: ${{ secrets.GUPSHUP_TO }} + GUPSHUP_FROM: ${{ secrets.GUPSHUP_FROM }} + run: | docker compose up -d --build sleep 5 diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..8618f710 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - GUPSHUP_API_KEY + - GUPSHUP_TO + - GUPSHUP_FROM build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/SMS/Gupshup.php b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php index 5b0804f2..30d9d1b4 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Gupshup.php +++ b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php @@ -1,4 +1,5 @@ apiKey, 'Content-Type: application/json', ]; - + $data = [ 'channel' => 'sms', 'src' => $message->getFrom(), diff --git a/tests/e2e/SMS/GupshupTest.php b/tests/e2e/SMS/GupshupTest.php new file mode 100644 index 00000000..91980568 --- /dev/null +++ b/tests/e2e/SMS/GupshupTest.php @@ -0,0 +1,31 @@ +send($message); + $result = json_decode($response, true); + + $this->assertArrayNotHasKey('errors', $result); + $this->assertArrayHasKey('message_id', $result); + $this->assertArrayHasKey('message', $result); + $this->assertArrayHasKey('balance', $result); + } +} From 38b381bd34bc57f52dfe2077637e89188cb3e79f Mon Sep 17 00:00:00 2001 From: HarshitVashisht11 Date: Wed, 18 Oct 2023 17:49:11 +0530 Subject: [PATCH 3/3] Updated Code --- src/Utopia/Messaging/Adapters/SMS/Gupshup.php | 4 ++-- tests/e2e/SMS/GupshupTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/Gupshup.php b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php index 30d9d1b4..1a245db8 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Gupshup.php +++ b/src/Utopia/Messaging/Adapters/SMS/Gupshup.php @@ -8,7 +8,7 @@ class Gupshup extends SMSAdapter { /** - * @param string $apiKey Gupshup API Key + * @param string $apiKey Gupshup API Key */ private string $apiKey; @@ -37,7 +37,7 @@ protected function process(SMS $message): string $url = 'https://api.gupshup.io/sm/api/v1/msg'; $headers = [ - 'Authorization: Bearer ' . $this->apiKey, + 'Authorization: Bearer '.$this->apiKey, 'Content-Type: application/json', ]; diff --git a/tests/e2e/SMS/GupshupTest.php b/tests/e2e/SMS/GupshupTest.php index 91980568..a9c4948e 100644 --- a/tests/e2e/SMS/GupshupTest.php +++ b/tests/e2e/SMS/GupshupTest.php @@ -10,7 +10,7 @@ class GupshupTest extends Base public function testSendSMS() { $apiKey = getenv('GUPSHUP_API_KEY'); - $to = getenv('GUPSHUP_TO'); + $to = [getenv('GUPSHUP_TO')]; $from = getenv('GUPSHUP_FROM'); $gupshup = new Gupshup($apiKey);