SMSGATEWAY.ME - How to use the PHP API? - php

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);
?>

Related

having a predetermined ban list for telegram bot when added to a group

This telegram bot tries to ban a predetermined user IDs each time added to a group. IDs are listed in a file. I'm using this telegram bot class and in webhook method.
$telegram = new Telegram($bot_id);
$chat_id = $telegram->ChatID();
$button = $telegram->text();
if ($button == "DoBan"){
$fn = fopen("ids.txt","r");
while(! feof($fn)) {
$result = fgets($fn);
$int_result = (int)$result;
$content = array('chat_id' => $chat_id, 'user_id' => "$int_result");
$telegram->kickChatMember($content);
}
fclose($fn);
$content2 = array('chat_id' => $chat_id, 'text' => "ban done! ");
$telegram->sendMessage($content2);
die();
}
But there is two problems here:
1. If IDs listed in our file haven't been banned before in the group bot is added to, the bot can't ban any of them. the point is if you ban IDs manually in any other group and perform a banning by bot there one time you can ban those IDs in any other group after that.
2. When bot receives the "DoBan" after it finishes the banning it get stuck in a some kind of loop and prints "ban done!" over and over like it's doing the banning all over again.
UPDATE:
Based on further researches there are two reasons for the two expressed problems
For the first problem: If your bot hasn't seen the user ID before it cannot ban it. So the bot has to see the user first somewhere, either by starting the bot or seeing that user inside the same group with bot
For the second problem: In case of an unsuccessful request telegram bot API thinks something is wrong with your server and requests again every few seconds so you have to add header("HTTP/1.1 200 OK"); to your script or do the increment on update_id
So this is the updated code
$telegram = new Telegram($bot_id);
header("HTTP/1.1 200 OK");
http_response_code(200);
$chat_id = $telegram->ChatID();
$result = $telegram->getData();
$text = $result['message'] ['text'];
$update = $result ['update_id'];
$result ['update_id'] = ++$update;
if ($button == "DoBan"){
$fn = fopen("ids.txt","r");
while(! feof($fn)) {
$result = fgets($fn);
$int_result = (int)$result;
$content = array('chat_id' => $chat_id, 'user_id' => "$int_result");
$telegram->kickChatMember($content);
}
fclose($fn);
$content2 = array('chat_id' => $chat_id, 'text' => "ban done! ");
$telegram->sendMessage($content2);
die();
}
So I need to know how should I exactly increase the update_id or what is the proper way to add header("HTTP/1.1 200 OK");becasue the problems still exist.
Based on further researches there are two reasons for the two expressed problems
for the first problem: If your bot hasn't seen the user ID before it cannot ban it. So the bot has to see the user first somewhere, either by starting the bot or seeing that user inside the same group with bot
for the second problem: In case of an unsuccessful request telegram bot API thinks something is wrong with your server and requests again every few seconds so you have to add header("HTTP/1.1 200 OK"); to your script or do the increment on update_id

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.

Insert data step by step in telegram bot

I am creating a telegram bot with php. I need to let user insert data step by step when they run the command /order. I do an example:
User: /order
Bot: I will help you to make an order
Bot: Insert the name
User: Ciccio (he has typed the name)
Bot: Ok, now insert your surname
User: Pasticcio (he has typed the surname)
and so on...
I thought I was in the correct way to reach my purpose... but not... something does not work... Here my code:
elseif(strcmp($text, "/order") === 0) <-Here the command
{
$response =
"I will help you.\n"
."\n"
."Insert your name:";
$parameters = ['chat_id' => $chatId, "text" => $response, "parse_mode" => "Markdown"];
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
$action_parameters = ['chat_id' => $chatId, "action" => "typing"];
$action_parameters["method"] = "sendChatAction";
echo json_encode($action_parameters);
$parameters2 = array('chat_id' => $chatId, "text" => "good! Now insert the surname");
$parameters2["method"] = "sendMessage";
echo json_encode($parameters2);
}
the code stop after I visualize the first message... it is like after I do my first echo json_encode($parameters); no code is runned anymore...
How can I reach my purpose?
Thank you
Do you use JSON response when received Webhook updates?
If yes, you need to make a request instead of print it to HTTP Response Body and log user input to your own database.
for any message your bot receives, you check the step of the user in your bot and you will send the right function (so the right question).
to do this you have to store users' steps. Please read my answer to this question.

Issues with twilio sms module in 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";
}

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