Skip to content

Commit e19dbc6

Browse files
Adding Messages Sandbox snippets (Vonage#98)
* Adding MEssages Sandbox snippets * add send method * add send method * add send method --------- Co-authored-by: James Seconde <[email protected]>
1 parent 99c6666 commit e19dbc6

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

.env-example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ FILE_URL=
4848
FILE_CAPTION=
4949
AUDIO_URL=
5050
VIDEO_URL=
51+
52+
## For Messages Sandbox
53+
MESSAGES_SANDBOX_URL=
54+
MESSAGES_SANDBOX_WHATSAPP_NUMBER=
55+
MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER=
56+
MESSAGES_SANDBOX_FB_ID=
57+
MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID=
58+
MESSAGES_SANDBOX_VIBER_SERVICE_ID=
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once __DIR__ . '../../config.php';
3+
require_once __DIR__ . '../../vendor/autoload.php';
4+
5+
$keypair = new \Vonage\Client\Credentials\Keypair(
6+
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
7+
VONAGE_APPLICATION_ID
8+
);
9+
10+
$client = new \Vonage\Client(
11+
$keypair,
12+
[
13+
'base_api_url' => MESSAGES_SANDBOX_URL
14+
]
15+
);
16+
17+
$message = new \Vonage\Messages\MessageType\Messenger\MessengerText(
18+
MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID,
19+
MESSAGES_SANDBOX_FB_ID,
20+
'This is a Messenger text message sent using the Vonage PHP SDK via the Messages Sandbox'
21+
);
22+
23+
$response = $client->messages()->send($message);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once __DIR__ . '../../config.php';
3+
require_once __DIR__ . '../../vendor/autoload.php';
4+
5+
$keypair = new \Vonage\Client\Credentials\Keypair(
6+
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
7+
VONAGE_APPLICATION_ID
8+
);
9+
10+
$client = new \Vonage\Client(
11+
$keypair,
12+
[
13+
'base_api_url' => MESSAGES_SANDBOX_URL
14+
]
15+
);
16+
17+
$viber = new \Vonage\Messages\MessageType\Viber\ViberText(
18+
MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER,
19+
MESSAGES_SANDBOX_VIBER_SERVICE_ID,
20+
'This is a Viber text message sent using the Vonage PHP SDK via the Messages Sandbox'
21+
);
22+
23+
$response = $client->messages()->send($message);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once __DIR__ . '../../config.php';
3+
require_once __DIR__ . '../../vendor/autoload.php';
4+
5+
$keypair = new \Vonage\Client\Credentials\Keypair(
6+
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
7+
VONAGE_APPLICATION_ID
8+
);
9+
10+
$client = new \Vonage\Client(
11+
$keypair,
12+
[
13+
'base_api_url' => MESSAGES_SANDBOX_URL
14+
]
15+
);
16+
17+
$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppText(
18+
MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER,
19+
MESSAGES_SANDBOX_WHATSAPP_NUMBER,
20+
'This is a WhatsApp text message sent using the Vonage PHP SDK via the Messages Sandbox via the Messages Sandbox'
21+
);
22+
23+
$response = $client->messages()->send($message);

0 commit comments

Comments
 (0)