Skip to content

Commit 8f08ab4

Browse files
author
Lorna Jane Mitchell
authored
Merge pull request Vonage#39 from Nexmo/verify-search-and-workflow-request
Verify Search and Workflow-based Request
2 parents b84c869 + bad3535 commit 8f08ab4

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-1
lines changed

.env-example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ MESSAGES_APPLICATION_ID=12a3b4cd-a1b2-1ab2-a1b2-a1234bc5d678
2121
VOICE_CALLBACK_TYPE=tel
2222
VOICE_CALLBACK_VALUE=447700900002
2323
VOICE_STATUS_URL=https://example.com/webhooks/status
24+
25+
# Verify API examples
26+
BRAND_NAME=Acme, Inc.
27+
CODE=
28+
NUMBER=
29+
REQUEST_ID=
30+
WORKFLOW_ID=4

verify/request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
77

8-
$verification = new \Nexmo\Verify\Verification(RECIPIENT_NUMBER, 'Acme Inc');
8+
$verification = new \Nexmo\Verify\Verification(NUMBER, 'Acme Inc');
99
$client->verify()->start($verification);
1010

1111
echo "Started verification, `request_id` is " . $verification->getRequestId();

verify/request_with_workflow.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
6+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
7+
8+
$options = getopt('n:w:b:h');
9+
$helpText = <<<ENDHELP
10+
Sends a verification request and allows setting a Workflow ID
11+
12+
Usage:
13+
php request_with_workflow.php -n <NUMBER> [-b <BRAND_NAME>] [-w <WORKFLOW_ID>]
14+
15+
NUMBER the telephone number to send the Verify request to
16+
BRAND_NAME is the name of the company sending the request. Defaults to 'Acme, Inc.'
17+
WORKFLOW_ID is the workflow ID to use. Must be between 1-5
18+
19+
Options can also be passed as environment variables.
20+
21+
ENDHELP;
22+
23+
if (array_key_exists('h', $options)) {
24+
echo $helpText;
25+
exit(1);
26+
}
27+
28+
if (!defined('NUMBER')) {
29+
define('NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null);
30+
}
31+
32+
if (!defined('BRAND_NAME')) {
33+
define('BRAND_NAME', (array_key_exists('b', $options)) ? $options['b'] : 'Acme, Inc');
34+
}
35+
36+
if (!defined('WORKFLOW_ID')) {
37+
define('WORKFLOW_ID', (array_key_exists('w', $options)) ? $options['w'] : 4);
38+
}
39+
40+
if (is_null(NUMBER)) {
41+
echo "Please supply a NUMBER to send a verification request to."
42+
. PHP_EOL
43+
. PHP_EOL
44+
. $helpText
45+
;
46+
exit(1);
47+
}
48+
49+
$verification = new \Nexmo\Verify\Verification(NUMBER, BRAND_NAME, ['workflow_id' => WORKFLOW_ID]);
50+
$client->verify()->start($verification);
51+
52+
echo "Started verification, `request_id` is " . $verification->getRequestId();

verify/search.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
6+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));
7+
8+
$options = getopt('h');
9+
$helpText = <<<ENDHELP
10+
Searches for a verify request
11+
12+
Usage:
13+
php search.php <REQUEST_ID>
14+
15+
REQUEST_ID is the ID of a verification event
16+
17+
ENDHELP;
18+
19+
if (array_key_exists('h', $options)) {
20+
echo $helpText;
21+
exit(1);
22+
}
23+
24+
if (!defined('REQUEST_ID')) {
25+
define('REQUEST_ID', (array_key_exists(1, $argv)) ? $argv[1] : null);
26+
}
27+
28+
if (is_null(REQUEST_ID)) {
29+
echo "Please supply a REQUEST_ID to search for."
30+
. PHP_EOL
31+
. PHP_EOL
32+
. $helpText
33+
;
34+
exit(1);
35+
}
36+
37+
try {
38+
$result = $client->verify()->search(REQUEST_ID);
39+
echo "Request has a status of " . $result->getStatus() . PHP_EOL;
40+
} catch (\Nexmo\Client\Exception\Request $e) {
41+
error_log("Client error: " . $e->getMessage());
42+
exit(1);
43+
} catch (\Nexmo\Client\Exception\Server $e) {
44+
error_log("Server error: " . $e->getMessage());
45+
exit(1);
46+
}

0 commit comments

Comments
 (0)