sending multiple messages using clickatell gateway - php

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'=...

Related

Sending a message to an user in moodle

I am currently trying to implement what should be a simple task and send a message to one and / or more users via Moodle.
In the process I found 2 guides, which confused me at first.
Messaging 2.0 and Message API. Both have some differences and I didn't understand if my plugin needs to register as a Message Producer or not.
Unfortunately, I just can't get my message to be sent. I logged in with the user and checked the mailbox, no message there. Any help is appreciated.
What I did:
Created message.php within my db - folder and inserted the following code:
<?php
defined('MOODLE_INTERNAL') || die();
$messageproviders = array (
'datenotification' => array (
)
);
After that I expanded my language file with this:
$string['messageprovider:datenotification'] = 'Reminder for a presentation';
Like the guide advised, I updated my plugin to insert my messageprovider in the table mdl_message_providers. Finally, I implemented the actual sending of the message.
$eventdata = new \core\message\message();
$eventdata->component = 'local_reminder'; // the component sending the message. Along with name this must exist in the table message_providers
$eventdata->name = 'datenotification'; // type of message from that module (as module defines it). Along with component this must exist in the table message_providers
$eventdata->userfrom = core_user::get_noreply_user(); // user object , no-reply
$eventdata->userto = $user; // user object from database
$eventdata->subject = 'Test message';
$eventdata->fullmessage = 'This is my test message';
$eventdata->fullmessageformat = FORMAT_PLAIN; // text format
$eventdata->fullmessagehtml = '<p>This is my test message</p>';
$eventdata->smallmessage = '';
$eventdata->courseid = $course_id; // This is required in recent versions, use it from 3.2 on https://tracker.moodle.org/browse/MDL-47162
$result = message_send($eventdata);
Debugging:
var_dump($eventdata); //-> All data is included
var_dump($result); // returns int(5), id of message, no error
Adding the comment as an answer for future reference
Check if the message is installed and enabled via site admin > messaging > notification settings or direct to yoursite/admin/message.php

Onlinecity SMPP - add new tlv parameters

I am using the OnlineCity SMPP client lib for sending SMS. It was working fine. But as per the new guideline of TRAI, we need to add the following new TLV parameters while sending SMS
group = smpp-tlv
name = EntityID
tag = 0x1400
type = octetstring
length = 30
smsc-id = ***
I tried this
// Prepare message
$ENTITY_ID = new SmppTag(0x1400, '****************');
$tags = array($ENTITY_ID);
$from = new SmppAddress($SMS_Params['senderid'],SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress($SMS_Params['phone'],SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);
$encodedMessage = utf8_encode($SMS_Params['message']);
// Send
$return_data = $smpp->sendSMS($from,$to,$encodedMessage,$tags);
I got the success response but didn't get any SMS. I checked with my smpp provider. They said that the additional TLV parameter is not there and that's why the SMS is not sent.
Do you guys have any idea, can we do it in my current code based on onlinecity library or should I do something else?.
You need to check if your octect strings are null terminated or not, by default the library is assuming it will be. So there is a variable $sms_null_terminate_octetstrings which needs to be reset if your provider does not end with null.
The above code change that Asterisk integrator has recommended says the same thing.
Rather than changing the code, if you can reset the flag based on your need, that should solve the problem.
For others who wanted to add new mandatory parameters should add like this using smpp-php library.
$tags = array(
new SmppTag(0x1400, your_pe_id),
new SmppTag(0x1401, your_template_id)
);
$message_id = $smpp->sendSMS($from, $to, $encodedMessage, $tags);
Remove "+(self::$sms_null_terminate_octetstrings ? 1 : 0)" from smppclient.class.php file
Actual Code :
$pdu = pack('a1cca'.(strlen($source->value)+1).'cca'.(strlen($destination->value)+1).'ccc'.($scheduleDeliveryTime ? 'a16x' : 'a1').($validityPeriod ? 'a16x' : 'a1').'ccccca'.(strlen($short_message)+(self::$sms_null_terminate_octetstrings ? 1 : 0))
Updated Code :
$pdu = pack('a1cca'.(strlen($source->value)+1).'cca'.(strlen($destination->value)+1).'ccc'.($scheduleDeliveryTime ? 'a16x' : 'a1').($validityPeriod ? 'a16x' : 'a1').'ccccca'.(strlen($short_message))

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.

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

PHP - Syncing MySQL Contacts with Exchange

As part of a PHP webapp I have MySQL contacts table. It is integrated throughout the app, allowing you add a contact, edit a contact or add a contact as a relation to another table. However, currently it is self-contained. The company would like it to sync with Exchange, so that contacts added to Exchange will show up on the webapp and contacts added on the webapp will show up through Exchange.
So I have two problems: 1) communicating with Exchange 2) syncing with Exchange.
As far as the basic communication goes, it looks like this library will be able to manage it https://github.com/jamesiarmes/php-ews. However, I am quite lost as to how to manage syncing and don't where to start.
The build-in way to sync items is via function called SyncFolderItems. Basically to Exchange everything, including contacts is a folder, so you'll just pass CONTACTS as DistinguishedFolderId in your sync request.
The sync works by donloading all the items for given account in batches of max 512 elements and after each batch it gives you SyncState as a refernce point for Exchange to know where you left off. So it gives you ability to do incremental sync.
Now, that's one way of course, meaning Exchange -> Your DB. The other way it aeound you should preform atomic updates/request - the moment you change/add/delete item form your db you should issue adequate request to Exchange server to keep data in sync, elese it'll be overwritten on your next SyncFolderItems.
You can read up more on SyncFolderItems # MSDN
If you'd like to see example of SyncFolderItems you can take a look # python version of EWSWrapper, it's been added in recently. Although it's python, you can still get the basic idea how to construct the request / handle response.
Hope this helps :)
I am aware that this topic is pretty old. However, for future reference find a solution below. It is using the above-mentioned library php-ews.
I have also just added this to the official php-ews wiki: https://github.com/jamesiarmes/php-ews/wiki/Calendar:-Synchronization
// Define EWS
$ews = new ExchangeWebServices($host, $username, $password, $version);
// fill with string from last sync
$sync_state = null;
$request = new EWSType_SyncFolderItemsType;
$request->SyncState = $sync_state;
$request->MaxChangesReturned = 512;
$request->ItemShape = new EWSType_ItemResponseShapeType;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->SyncFolderId = new EWSType_NonEmptyArrayOfBaseFolderIdsType;
$request->SyncFolderId->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType;
$request->SyncFolderId->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$response = $ews->SyncFolderItems($request);
$sync_state = $response->ResponseMessages->SyncFolderItemsResponseMessage->SyncState;
$changes = $response->ResponseMessages->SyncFolderItemsResponseMessage->Changes;
// created events
if(property_exists($changes, 'Create')) {
foreach($changes->Create as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// updated events
if(property_exists($changes, 'Update')) {
foreach($changes->Update as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// deleted events
if(property_exists($changes, 'Delete')) {
foreach($changes->Delete as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}

Categories