Issues with twilio sms module in PhP - php

I am trying to test the twilio sms reminder library with a trial account I created for this purpose. The problem is that when I launch the file from my XAMPP "webroot" folder that also contains the "Twilio" folder I see nothing, just a blank page on Mozilla Firefox while on IE the error code 500 is up. Please find my code below thank you.
<?php
require $_SERVER['DOCUMENT_ROOT']."/openemr/twilio/Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+14158675309" => "Curious George",
"+14158675310" => "Boots",
"+14158675311" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"+12057198157",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}

Related

Plivo PHP API 4.0, can't get callstatus or duration (action URL does not execute?)

I hope you can help me with an issue with phone call dialings using Plivo PHP (new SDK 4.0). First I will indicate what I want to achieve:
- A client on my website wants to talk with an agent of main, so he introduces his telephone number in a form, choose an agent, and finally when submit, the website connect both of them dialing (this works). But then, (here begin my problems), I can't retrieve the call details (status, duration, initial and end dates of the call, etc...) for invoicing the client according to some of these details.
Edited 2018/02/23:
Ramya, the 600 error has dissapeared and everything seems to be ok as I see in the Plivo debug log. Below are my new codes (I think better done thanks to your instructions), and then, I show you the Plivo debud log (perhaps it's better you can see it inside my account, call made Feb 23, 2018 18:33:15), and finally I see my server debug error log is empty!.
The main problem is that dialstatus.php file, although seems to receive the parameters, I don't know how to access them because dialstatus.php does not execute showing the data in my monitor (in my code for example, this line never shows in the monitor screen:)
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
So even though it receives the parameters, I can not access them to manipulate them, print them on the screen, do ifs with them, etc. May it be perhaps a permission problem with the files? (These php files have 6,4,4 permissions on my server, the same as the others).
Thank you!
Code 1: makecall.php
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("**********", "**************************");
$telefono_cliente = "34*******";
$telefono_experto = "34*********";
$duracion = 50;
try {
$response = $client->calls->create(
"3491111111",
[$telefono_experto],
"https://www.ejemplo.com/llamar/response.php?telf=$telefono_cliente",
'POST',
[
'time_limit' => $duracion,
]
);
$id = $response->requestUuid;
echo "<br>Este es el requestUuid: " . $id . "<br><br>";
}
catch (PlivoRestException $ex) {
print_r($ex);
}
?>
Code 2: response.php
require 'vendor/autoload.php';
use Plivo\XML\Response;
$resp = new Response();
$params = array(
'callerId' => '3491111111',
'action' => "https://www.ejemplo.com/llamar/dialstatus.php",
'method' => "POST",
'redirect' => "false"
);
$body3 = 'Desde ejemplo un cliente desea hablar con usted.';
$params3 = array(
'language' => "es-ES", # Language used to read out the text.
'voice' => "WOMAN" # The tone to be used for reading out the text.
);
$resp->addSpeak($body3,$params3);
$dial = $resp->addDial($params);
//$number = "34**********";
$number = $_GET['telf'];
$dial->addNumber($number);
Header('Content-type: text/xml');
echo($resp->toXML());
/*
Output:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Speak language="es-ES" voice="WOMAN">Desde ejemplo un cliente desea hablar con usted.</Speak>
<Dial redirect="false" method="POST" action="http://www.ejemplo.com/llamar/dialstatus.php" callerId="3491111111">
<Number>34********</Number>
</Dial>
</Response>
*/
?>
Code 3: dialstatus.php
// Print the Dial Details
$estado = $_REQUEST['DialStatus'];
$aleg = $_REQUEST['DialALegUUID'];
$bleg = $_REQUEST['DialBLegUUID'];
echo "Status = $estado, Aleg UUID = $aleg, Bleg UUID = $bleg";
?>
Plivo Sales Engineer here.
Redirect = true is used only when you want to continue the call by returning another XML in your action URL. For you use case, you don't have to use this parameter. Even if the Redirect is set to false, Plivo will make a request to the action URL with a list of parameters. I looked into your account (here) and I can see this request getting sent with DialStatus, ALegUUID, BLegUUID along with other parameters.
Dial Action URL is the best place to know the DialStatus and DialHangupCause.
You can find the call duration and billing amount in Hangup URL request as well. This Hangup URL can be configured in your first API call (to the expert). By default, hangup URL is set to Answer URL.
Please raise a support ticket with us for further assistance.

Twillio Php api

There
I'm Using Twillio Example api
// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php,
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "ACea465f2e60ae87332cf47adb0e4aad64";
$AuthToken = "your_auth_token";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+15558675309" => "Curious George",
"+15558675308" => "Boots",
"+15558675307" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
"+15017250604",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
and here is my code
// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php,
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "accountsid";
$AuthToken = "authtoken";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"my-number-goes-here" => "Ali M. Ayad",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
"+13862593325",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey Ali This is test message form the api"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
when i put this code and i change the auth and id and the number is give my this message
Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'Authentication Error - invalid username' in C:\AppServ\www\tw\Services\Twilio.php:297 Stack trace: #0 C:\AppServ\www\tw\Services\Twilio.php(180): Base_Services_Twilio->_processResponse(Array) #1 C:\AppServ\www\tw\Services\Twilio\ListResource.php(92): Base_Services_Twilio->createData('/2010-04-01/Acc...', Array) #2 C:\AppServ\www\tw\Services\Twilio\Rest\Messages.php(24): Services_Twilio_ListResource->_create(Array) #3 C:\AppServ\www\tw\Services\Twilio\Rest\Messages.php(71): Services_Twilio_Rest_Messages->create(Array) #4 C:\AppServ\www\tw\sendnotifications.php(48): Services_Twilio_Rest_Messages->sendMessage('+13862593325', '+201063378955', 'Hey Ali This is...') #5 {main} thrown in C:\AppServ\www\tw\Services\Twilio.php on line 297
i'm using appserv
As the error message says (almost) clearly:
Authentication Error - invalid username
Assuming you are already registered at twilio; make sure you correctly defined your username and token in the real code you use:
Re-check again and again your username (and AuthToken also) for possible encoding issues and/or mistakes involving:
Correctly matching character case,
Trailing spaces, and
Special characters.
Also verify that your account is still valid at twilio.
"Authentication Error - invalid username'"
Your AccountSid and AuthToken are the "master keys" to your account. To authenticate using these "master keys," use HTTP basic auth with the username set to your AccountSid and the password set to your AuthToken. Your AccountSid and AuthToken can be found on your Account Dashboard.

SMSGATEWAY.ME - How to use the PHP API?

I would like to use an SMS Gateway PHP API but I don't success to use it. I downloaded on my phone with android the software from SMSGATEWAY.ME and I created an account.I have also a free web server and I uploaded on it two documents :
their PHP API Library "smsGateway.php" that peoples can find here :
https://smsgateway.me/sms-api-libraries/sms-gateway-me-php.zip
my file "test.php" :
<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');
$deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
$number = '+1234567891'; //the number I want to SMS
$message = 'Hello World!'; //my message
$options = [
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];
//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
?>
But when I visit with my browser http://mywwebsite.com/test.php, it doesn't send SMS, do you know why please ? Can you help me to fix this problem please ? (the gateway on my phone is still active).
Thank you in advance !
Best regards
Your code is correct. If you want to display the result write the following line after $result variable
echo json_encode($result);
So your code will look like this
<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('my_email_on_their_website', 'my_password_for_this_account');
$deviceID = 111111; //the number of my device, displayed on their website or on the software installed on my phone
$number = '+1234567891'; //the number I want to SMS
$message = 'Hello World!'; //my message
$options = [
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent
];
//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
echo json_encode($result);
?>

Whatsapp API php code request

Following is my code to CodeRequest.
$username = "91xxxxxxxxxx";
$identity = strtolower(urlencode(sha1($username, true)));
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest();
print_r($r);
It gives the response as
stdClass Object ( [status] => sent [length] => 6 [method] => sms [retry_after] => 1805 )
But I'm not receiving message. Any suggestions please.
My other questions.
Is there any restriction to request code.(Every time I use new mobile number).?
For example I request a code for mobile number xxx with user agent galaxys3 shall i request another code with mobile number yyy using the same user agent?
I'm using WhatsAPI-Official
Finally I received code to mobile.
$username = "91xxxxxxxxxx";
$identity = "myIdentity";
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest('sms',$carrier);
(or)
$r = $w->codeRequest('voice',$carrier); //Voice service is fast compared to sms
$carrier is getting from networkinfo.csv file.
carrier is nothing but mobile network operator(Airtel,Idea etc.,) according to your mobile country code(mcc) and mobile network code (mnc).
You can get the mnc and mcc codes from mobile-network-codes-country-codes
Get mcc and mnc codes with your location and operation match them with networkinfo.csv to get carrier name.
Eg: My number is 919xxxxxx
country - india ( Andhra Pradesh )
operator - Idea
For above link mcc and mnc are for my number is 404 & 7
Now check those codes in networkinfo.csv file
i.e
404,1028,007,7,in,India,91,Idea Cellular Ltd.4
Here 404 -> mcc
and 007 -> mnc
My carrier name is Idea Cellular Ltd.4
If you send correct carrier name you will get sms/call to mobile.
Try this piece of code.
$destinationPhone = 'xxxxxxxxxxxx';
$w = new WhatsProt($userPhone, $userIdentity, $userName, $debug);
$w->Connect();
$w->LoginWithPassword($password);
$w->Message($destinationPhone, $argv[1]);
or more info refer this link..
http://blog.philippheckel.com/2013/07/07/send-whatsapp-messages-via-php-script-using-whatsapi/#Send-WhatsApp-messages

sending multiple messages using clickatell gateway

I used php server side to connect with clickatell messages service , i used the soap api technique to make the connection . it is working .but in my code , i can send just one message at the same time , here is the code :
function actionSendSMS(){
$msgModel = new Messages();
$settModel = new Settings();
$setRows = $settModel->findAll();
$usr=$setRows[0]->clickatell_usr;
$pwdRows = $settModel->findAll();
$pwd=$pwdRows[0]->clickatell_pwd;
$api_idRows = $settModel->findAll();
$api_id=$api_idRows[0]->clickatell_api_id;
$msgModel->findAllBySql("select * from messages where is_sent=0 and
send_date=".date("m/d/Y"));
$client = new SoapClient("http://api.clickatell.com/soap/webservice.php?WSDL");
$params = array('api_id' => $api_id,'user'=> $usr,'password'=> $pwd);
$result = $client->auth($params['api_id'],$params['user'],$params['password']);
$sessionID = substr($result,3);
$callback=6;
// echo $result."<br/>";
// echo $sessionID;
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=>
$usr,'password'=>$pwd,
'to'=>array('962xxxxxxx'), 'from'=>"thetester",'text'=>'this is a sample test
message','callback'=>$callback);
$result2 = $client->sendmsg($params2['session_id'],
$params['api_id'],$params['user'],$params['password'],
$params2['to'],$params2['from'],$params2['text'],$params2['callback']);
print_r( $result2)."<br/>";
$apimsgid= substr($result2[0],4);
$rowsx=Messages::model()->findAllBySql("select * from messages where is_sent=0 and
send_date='".date("m/d/Y")."'");
for($i=0;$i<count($rowsx);$i++)
{
$rowsx[$i]->clickatell_id=$apimsgid;
$rowsx[$i]->save();
}
//echo $apimsgid."<br/>";
if (substr($result2[0], 0,3)==='ERR' && (!(substr($result2[0], 0,2)==='ID'
) ))
{
echo 'Connot Routing Message';
}
.... now you see that this code will send one message at the same time , forget about the id , its for personal purpose , now this service i have to modify it , to send multiple messages at the same time , and i will give every message an unique ID , so now my problem is : is there any one knows if there is a service to send multiple sms at the same time ;
as in my code i fill the information for one message ,but i need a service to send multiple sms , does any body can give me a link to this service , i made many searches but there is no answer i have found
Try startbatch command to send multiple messages at the same time (it also supports personalized). However, it is not based soap, it is based http api.
Have you tried
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx', '962xxxxxxx', '962xxxxxxx'), 'from'=>"thetester",'text'=...
or
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx,962xxxxxxx,962xxxxxxx'), 'from'=>"thetester",'text'=...

Categories