Skip to main content

Hi Team

I want to send text.I try this code for sending sms:



<?php



require('vendor/autoload.php');


use RingCentralSDKSDK;



// Parse the .env file

$dotenv = new DotenvDotenv(getcwd());

$dotenv->load();



try {



// Create SDK instance

$rcsdk = new SDK($_ENV['GLIP_APPKEY'], $_ENV['GLIP_APPSECRET'] , $_ENV['GLIP_SERVER'], 'Demo', '1.0.0');


// Create Platform instance

$platform = $rcsdk->platform();

/*

* Using the caching mechanism

*/

$cacheDir = __DIR__ . DIRECTORY_SEPARATOR . '_cache';

$file = $cacheDir . DIRECTORY_SEPARATOR . 'platform.json';


$cachedAuth = array();


if (file_exists($file)) {


$cachedAuth = json_decode(file_get_contents($file), true);

}


$platform->auth()->setData($cachedAuth);


// To login user

$rc=$platform->login($_ENV['username'],$_ENV['extension'],$_ENV['password']);


$apiResponse = $rcsdk->platform()->post('/account/~/extension/~/sms', array(

'from' => array('phoneNumber' => 'your-ringcentral-sms-number'),

'to' => array(

array('phoneNumber' => 'mobile-number'),

),

'text' => 'Test from PHP',

));

/*

* Setup Webhook Subscription

*/

$apiResponse = $platform->post('/subscription',array(

"eventFilters"=>array(

"/restapi/v1.0/glip/groups",

"/restapi/v1.0/glip/posts"

),

"deliveryMode"=>array(

"transportType"=> "WebHook",

"address"=>$_ENV['GLIP_WEBHOOK_URL']

)

));


print PHP_EOL . "Wohooo, your Bot is Registered now." . PHP_EOL;


} catch (Exception $e) {


print 'Webhook Setup Error: ' . $e->getMessage() . PHP_EOL;

}


after running this code I get this error:



Please tell me if i miss something in this.Also suggest docs for sending msg from local machine.



Are you trying to send SMS using a Bot? The code in index.php is used to set up a subscription via webhook for the bot. I am not very sure about what you are trying to achieve.

However, we have a demo in our Official PHP SDK to send SMS. Kindly go on and read below to know more:

API Documentation: 
https://developer.ringcentral.com/api-docs/latest/index.html#!#RefSMSMessages.html

SMS Demo:
https://github.com/ringcentral/ringcentral-php#send-sms---make-post-request

Hope this helps!



Yes, we are trying to send SMS using a Bot. We already have referred demo from Official PHP SDK to send SMS and we got error shown in screenshot attached in previous thread. Could you provide your insight on error ? Also let us know if we are missing something.

Can you check or post the content (w/o values, just the key) of the env file. It looks like your key in the env file does not match with the key "username" in your index.php. Looks like you copied/pasted the code from different example and the env was taken from the botman example which is GLIP_USERNAME not username.

I cannot say much w/o seeing some of the code though.

+ Phong
I agree with Phong. 

Also, please note that if your application is of the type "Server/Bot" you cannot authorize using the Password Flow 

Since your app was authorized using the OAuth2.0, the adapter stores the token in a folder named _cache which you could re-use to make API calls. 

Make sure to delete the below line inside index.php and re-try:
$rc=$platform->login($_ENV['username'],$_ENV['extension'],$_ENV['password']);


OK sir. I try that code. Thanks for help.
I want more help. Can you please help to resolve?
I am successfully registered my bot.Now I want to add API in that like (SMS,Meeting,Call,).
  1. I try first SMS API as above mention which I won't be able to implement in my local machine file.
  2. I try this same from UI in that when I run post and get method for SMS then it's working. 
  3. Can you please tell me how to add this code in my local machine code(php).
  4. Where we can see the send msg?
  5. I search every where but i won't be able to find right option to see my send message in my inbox ?
Please guide me..





Are you trying to send an SMS from Glip using the Bot you have created above? For ex: by typing in the below command:



I have added the functionality to send sms in the webhook.php file as below:

$botman->hears('send sms to {number}', function (BotMan $bot, $query) {
    $bot->reply($query);
})->driver(GlipBotman::class);

So the Adapter listens to the message and parses the {number} and sends SMS. Kindly try the updated branch and provide us your feedback:
https://github.com/ringcentral/glip-botman/tree/bot-provisioner

Please note the changes in the .env file below:
https://github.com/ringcentral/glip-botman/tree/bot-provisioner#configure-your-bot

If there is any concern, please feel free to open issue in the Github Repository below:
https://github.com/ringcentral/glip-botman/issues

Hope this information helps!


Reply