diff --git a/examples/whatsapp.php b/examples/whatsapp.php index 6d96bf0..e28ca44 100644 --- a/examples/whatsapp.php +++ b/examples/whatsapp.php @@ -1,26 +1,12 @@ whatsapp->send([ - 'to' => '79150000000', - 'txt' => 'GreenSMS Node SDK', - 'from' => '79150000000', + 'to' => '79260000000', + 'txt' => '1234 is your verification code.', + 'from' => 'GREENSMS', 'tag' => 'test-sdk-node' ]); +printf("WhatsApp Request ID: %s\n", $response->request_id); -echo "Whatsapp Request Id: " . $response->request_id; -echo "\n\n"; - -$response = $client->whatsapp->status([ - 'id' => '79442f1f-17a8-42bb-9f6f-4affc8788e7e', -]); - -echo "Whatsapp Status: \n"; -print_r($response); - -$response = $client->whatsapp->webhook([ - 'url' => 'http://test.url', -]); - -echo "Whatsapp Webhook: \n"; -print_r($response); +$response = $client->whatsapp->status(['id' => $response->request_id]); +printf("WhatsApp Status: %s\n", var_export($response, 1)); diff --git a/src/Api/Modules.php b/src/Api/Modules.php index 400771e..738323f 100644 --- a/src/Api/Modules.php +++ b/src/Api/Modules.php @@ -101,7 +101,22 @@ public static function getModules() ], ] ] - ], + ], + 'whatsapp' => [ + 'schema' => $schema['vk'], + 'versions' => [ + 'v1' => [ + 'send' => [ + 'args' => ['params'], + 'method' => 'POST', + ], + 'status' => [ + 'args' => ['params'], + 'method' => 'GET', + ], + ] + ] + ], 'pay' => [ 'schema' => $schema['pay'], 'versions' => [ diff --git a/tests/WhatsappTest.php b/tests/WhatsappTest.php new file mode 100644 index 0000000..acc59e7 --- /dev/null +++ b/tests/WhatsappTest.php @@ -0,0 +1,52 @@ +utility = new Utility(); + } + + public function testCanSendMessage() + { + $phoneNum = $this->utility->getRandomPhone(); + $params = [ + 'to' => $phoneNum, + 'txt' => '1234 is your verification code.', + 'from' => 'GREENSMS', + 'tag' => 'test-sdk-node' + ]; + + $response = $this->utility->getInstance()->whatsapp->send($params); + $this->assertObjectHasAttribute('request_id', $response); + return $response->request_id; + } + + /** + * @depends testCanSendMessage + */ + /* + public function testCanFetchStatus($requestId) + { + sleep(2); + $response = $this->utility->getInstance()->whatsapp->status(['id' => $requestId, 'extended' => true ]); + $this->assertObjectHasAttribute('status', $response); + } + */ + public function testRaisesValidationException() + { + try { + $response = $this->utility->getInstance()->whatsapp->send([]); + $this->fail("Shouldn't send Whatsapp without parameters"); + } catch (Exception $e) { + $this->assertObjectHasAttribute('message', $e); + $this->assertEquals('Validation Error', $e->getMessage()); + } + } +}