From 0649274a0d746738420dfd23e90aaffda480a633 Mon Sep 17 00:00:00 2001 From: LunarMarathon Date: Tue, 3 Oct 2023 16:39:11 +0530 Subject: [PATCH 1/3] Add AfricasTalking Adapter --- .../Messaging/Adapters/SMS/AfricasTalking.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php diff --git a/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php b/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php new file mode 100644 index 00000000..2f0ce19e --- /dev/null +++ b/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php @@ -0,0 +1,56 @@ +request( + method: 'POST', + url: "https://api.africastalking.com/version1/messaging", + headers: [ + 'apiKey: '.$this->apiKey, + 'Content-Type: application/json', + ], + body: \json_encode([ + 'username' => $this->username, + 'to' => $message->getTo(), + 'message' => $message->getContent(), + 'from' => $message->getFrom(), + ]), + ); + } +} \ No newline at end of file From 458d64b0b42ea80f8e60a892cf6007a529e206ff Mon Sep 17 00:00:00 2001 From: LunarMarathon Date: Wed, 4 Oct 2023 12:22:06 +0530 Subject: [PATCH 2/3] Update AfricasTalking.php --- .../Messaging/Adapters/SMS/AfricasTalking.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php b/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php index 2f0ce19e..71f15d63 100644 --- a/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php +++ b/src/Utopia/Messaging/Adapters/SMS/AfricasTalking.php @@ -37,19 +37,20 @@ public function getMaxMessagesPerRequest(): int * @throws \Exception */ protected function process(SMS $message): string - { + { return $this->request( method: 'POST', - url: "https://api.africastalking.com/version1/messaging", + url: "https://api.sandbox.africastalking.com/version1/messaging", + // live endpoint: url: "https://api.africastalking.com/version1/messaging ", headers: [ 'apiKey: '.$this->apiKey, - 'Content-Type: application/json', + 'Content-Type: application/x-www-form-urlencoded', + 'Accept: application/json', ], - body: \json_encode([ + body: \http_build_query([ 'username' => $this->username, - 'to' => $message->getTo(), + 'to' => $message->getTo()[0], 'message' => $message->getContent(), - 'from' => $message->getFrom(), ]), ); } From 1fd093eb26d793ab8cfabc7dc7e1d1489495896c Mon Sep 17 00:00:00 2001 From: LunarMarathon Date: Wed, 4 Oct 2023 12:24:06 +0530 Subject: [PATCH 3/3] Added test for the adapter --- tests/e2e/SMS/AfricasTalkingTest.php | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/e2e/SMS/AfricasTalkingTest.php diff --git a/tests/e2e/SMS/AfricasTalkingTest.php b/tests/e2e/SMS/AfricasTalkingTest.php new file mode 100644 index 00000000..6b85250e --- /dev/null +++ b/tests/e2e/SMS/AfricasTalkingTest.php @@ -0,0 +1,34 @@ +send($message); + $result = \json_decode($response, true); + + $this->assertNotEmpty($result); + } +} \ No newline at end of file