-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreceive-reply.php
More file actions
39 lines (32 loc) · 1.37 KB
/
receive-reply.php
File metadata and controls
39 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Symfony\Component\Dotenv\Dotenv;
use RingCentral\SDK\Subscription\Events\NotificationEvent;
use RingCentral\SDK\Subscription\Subscription;
require('vendor/autoload.php');
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
$rcsdk = new RingCentral\SDK\SDK(getenv('RINGCENTRAL_CLIENT_ID'),
getenv('RINGCENTRAL_CLIENT_SECRET'),
getenv('RINGCENTRAL_SERVER_URL'));
$platform = $rcsdk->platform();
$platform->login( getenv('RINGCENTRAL_USERNAME'),
getenv('RINGCENTRAL_EXTENSION'),
getenv('RINGCENTRAL_PASSWORD'));
$handler = function (NotificationEvent $e) use ($platform) {
$payload = $e->payload();
$sender = $payload['body']['from']['phoneNumber'];
$r = $platform->post('/account/~/extension/~/sms', array(
'from' => array('phoneNumber' => getenv('RINGCENTRAL_USERNAME')),
'to' => array(
array('phoneNumber' => $sender),
),
'text' => 'This is an automatic reply',
));
print_r('SMS replied: ' . $r->json()->id . "\n");
};
$subscription = $rcsdk->createSubscription();
$subscription->addEvents( array('/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS') );
$subscription->addListener(Subscription::EVENT_NOTIFICATION, $handler);
$subscription->setKeepPolling(true);
$r = $subscription->register();
?>