News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
PHP Webhook Subscription Sandbox vs Production Different Behavior on Sending and Receiving SMS
Tags: rest api
Mar 27, 2020 at 2:57am   •   4 replies  •  0 likes
Theresa Theresa

Hi There,

We have been able to successfully create, delete webhook subscriptions using PHP and REST API. Everything was working perfectly fine until we had our app published for production and we have noticed a strange behavior or unexpected behavior which is not present in Sandbox mode.

In Sandbox: We sent a sms which works fine and once someone replies we get that replies from Webhook and process it as required.

In Production: Once we sent an sms our webhook automatically gets called for the sent SMS and is responding back with the data of sent SMS not received. That behavior is not present in Sandbox mode and our webbook is only being called once we have a reply from someone.

Can you please help me understand why is that and where is something wrong? Why we have different behavior from the same app and account.

Shouldn't this be the same as Sandbox. Webhook should only be called once we have replies against registered events of instant sms?


Thanks,

Yasir

4 Answers
answered on Mar 27, 2020 at 8:54am  

Your question is clear except the problem described in the Production paragragh.

In Production: Once we sent an sms our webhook automatically gets called for the sent SMS and is responding back with the data of sent SMS not received. That behavior is not present in Sandbox mode and our webbook is only being called once we have a reply from someone.

Can you clarify this "responding back with the data of sent SMS not received ?" and "and our webbook is only being called once we have a reply from someone."

If you can't explain differently, it would be helpful to post the code where you implement the incoming message handling and sending a message back to the sender etc.


 0
answered on Mar 29, 2020 at 4:00am  

I'm Sorry while Posting your editor seemed to be working fine and was displaying code as if its in coding editor. But once its posted. I see the weiredness of the view now. But you can copy it and see it. As its working example.


 0
answered on Mar 29, 2020 at 3:57am  

Hi @Phong Vu,

I hope you are doing good. Let me explain here.

Sandbox Behavior:

  1. We can send a sms and our webhook we have created is not called once we sent an sms.
  2. We can receive a SMS. Here our webbook is called with incoming message data.

That is expected beviour and working fine. We can send and receive as many SMS we want. Webhook is only being called/invoked once someone replies to any of the sent sms. Make sense?


Production Behavior:

  1. We can send a sms and our webhook gets called and sends the data back to us which we sent as a "Sent SMS". Should that happen? We are not receiving the sent SMS as is back to us on our call back once we send it during Sandbox mode.
  2. We can receive a SMS. Here our webhook is called with incoming message data.

That is expected beviour and working fine in case of incoming/receiving message.

Below is the working code of Webhook:

<?php 
if (isset($_REQUEST['webhookcallback'])) { 
  if (array_key_exists('HTTP_VALIDATION_TOKEN', $_SERVER)) { 
    $response = new Response(); 
    $response->setStatusCode(Response::STATUS_CODE_200); 
    $response->getHeaders()->addHeaders(array( 'Validation-Token' => $_SERVER['HTTP_VALIDATION_TOKEN'], )); 
    return $response->setContent("Validation-Token: Returned"); 
}else{ 
  //We have are processing the Received Data here 
  // This portion should be called only if we have an incoming/Receiving SMS? 
  //Processing the webhook Received Data $firstParam = ""; 
  // Query Params we sent while we created the subscription $secondParam = "";
  // Query Params we sent while we created the subscription 
  $jsonStr = file_get_contents('php://input'); 
  $jsonObj = json_decode($jsonStr, TRUE); 
  // Below is our business Logic to deal with SMS. 
}


Below is the working code of Creating the Webhook Subscription:

$body = array(
 'eventFilters' => array(
 '/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS' 
 ),
 'deliveryMode' => array(
 'transportType' => 'WebHook',
 'address' => $webhookUrl,
 'encryption' => false,
 ),
 'expiresIn' => 630720000
 );
 $params = json_encode($body);
 
 try {
   $part_uri = '/restapi/v1.0/subscription';
   //Set the content type to application/json
   $headers[] = 'Authorization: Bearer ' . $_SESSION['rAccessCode'];
   $headers[] = 'Content-Type: application/json';
 
   //Initiate cURL.
   $ch = curl_init($this->_api_uri . $part_uri);
   //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
   curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_TIMEOUT, 20);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

   //Execute the request
   $result = curl_exec($ch);
   return json_decode($result
 } catch (Zend_Rest_Client_Exception $e) {
   $errors[] = '[' . $e->getCode() . ']:' . $e->getMessage();
 } catch (Exception $e) {
   $errors[] = '[' . $e->getCode() . ']:' . $e->getMessage();
 }
 if ($errors) {
   print_r($errors);
   exit;
 }

Please guide us through this and let me know if you have any more questions or suggestions?

thanks

Yasir


 0
answered on Mar 29, 2020 at 9:59am  

Based on the filter you specified for your webhook notification below:

$body = array(
 'eventFilters' => array(
 '/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS' 
 ),

You will receive SMS notification (with the message body) whenever there is an incoming SMS to ANY PHONE NUMBERS belong to the "user extension" (the user who logged in the app).

I can confirm that this filter will not subscribe for outgoing SMS notification. => That is why you confirmed it works correctly on your Sandbox account.

I suspect that in your production test, you sent a test message to one of the phone numbers which belongs to the same user who is being logged in your app.

To double check this, use your personal mobile number, or even use the phone number of your sandbox to send an SMS message to the phone number of the user (who is logged in the app). And reply to the sandbox number.

If this still does not work. Give me your app client id and the user extension number (for example 102, not the phone number) so I can have a look at it.


 0
answered on Mar 29, 2020 at 9:19am  
<?php
 if (isset($_REQUEST['webhookcallback'])) {
   if (array_key_exists('HTTP_VALIDATION_TOKEN', $_SERVER)) {
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_200);
     $response->getHeaders()->addHeaders(array(
       'Validation-Token' => $_SERVER['HTTP_VALIDATION_TOKEN'],
     ));
     return $response->setContent("Validation-Token: Returned");
   }else{
     //We have are processing the Received Data here
     // This portion should be called only if we have an incoming/Receiving SMS?
     //Processing the webhook Received Data
     $firstParam = ""; // Query Params we sent while we created the subscription
     $secondParam = "";// Query Params we sent while we created the subscription

     $jsonStr = file_get_contents('php://input');
     $jsonObj = json_decode($jsonStr, TRUE);

     // Below is our business Logic to deal with SMS.

?>



 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us