Skip to content

Commit

Permalink
fix: WA
Browse files Browse the repository at this point in the history
  • Loading branch information
2naive committed Feb 12, 2024
1 parent 4b5a325 commit 1fd62cc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 21 deletions.
26 changes: 6 additions & 20 deletions examples/whatsapp.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<?php
include_once('init.php');

$response = $client->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));
17 changes: 16 additions & 1 deletion src/Api/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
52 changes: 52 additions & 0 deletions tests/WhatsappTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use GreenSMS\Tests\Utility;
use GreenSMS\GreenSMS;
use GreenSMS\Tests\TestCase;

final class WhatsappTest extends TestCase
{
private $utility = null;

public function setUp(): void
{
$this->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());
}
}
}

0 comments on commit 1fd62cc

Please sign in to comment.