[Vtigercrm-developers] SMS sender problem with Versatile?
kiran
kiranraju.jakka at gmail.com
Thu Jan 18 12:09:13 GMT 2018
Hello,
According to basic configuration i configured SMS Server Notifier with the
below url..
http://sms.versatilesmshub.com/api/mt/SendSMS?user=demo&password=demo123&senderid=WEBSMS&channel=Trans&DCS=0&flashsms=0&number=91989xxxxxxx&text=test
message&route=##
I modified MySender.php to Versatile.php and code should look like,
------**-------
<?php
class SMSNotifier_Versatile_Provider implements
SMSNotifier_ISMSProvider_Model {
private $userName;
private $password;
private $parameters = array();
const SERVICE_URI = 'http://sms.versatilesmshub.com/api/mt';
private static $REQUIRED_PARAMETERS = array('senderid', 'channel', 'DCS',
'flashsms', 'route');
/**
* Function to get provider name
* @return <String> provider name
*/
public function getName() {
return 'Versatile';
}
/**
* Function to get required parameters other than (userName, password)
* @return <array> required parameters list
*/
public function getRequiredParams() {
return self::$REQUIRED_PARAMETERS;
}
/**
* Function to get service URL to use for a given type
* @param <String> $type like SEND, PING, QUERY
*/
public function getServiceURL($type = false) {
if($type) {
switch(strtoupper($type)) {
case self::SERVICE_AUTH: return self::SERVICE_URI . '/http/auth';
case self::SERVICE_SEND: return self::SERVICE_URI . '/SendSMS';
case self::SERVICE_QUERY: return self::SERVICE_URI . '/http/querymsg';
}
}
return false;
}
/**
* Function to set authentication parameters
* @param <String> $userName
* @param <String> $password
*/
public function setAuthParameters($userName, $password) {
$this->userName = $userName;
$this->password = $password;
}
/**
* Function to set non-auth parameter.
* @param <String> $key
* @param <String> $value
*/
public function setParameter($key, $value) {
$this->parameters[$key] = $value;
}
/**
* Function to get parameter value
* @param <String> $key
* @param <String> $defaultValue
* @return <String> value/$default value
*/
public function getParameter($key, $defaultValue = false) {
if(isset($this->parameters[$key])) {
return $this->parameters[$key];
}
return $defaultValue;
}
/**
* Function to prepare parameters
* @return <Array> parameters
*/
protected function prepareParameters() {
$params = array('user' => $this->userName, 'password' => $this->password);
foreach (self::$REQUIRED_PARAMETERS as $key) {
$params[$key] = $this->getParameter($key);
}
return $params;
}
/**
* Function to handle SMS Send operation
* @param <String> $message
* @param <Mixed> $toNumbers One or Array of numbers
*/
public function send($message, $toNumbers) {
if(!is_array($toNumbers)) {
$toNumbers = array($toNumbers);
}
$params = $this->prepareParameters();
$params['text'] = $message;
$params['number'] = implode(',', $toNumbers);
$serviceURL = $this->getServiceURL(self::SERVICE_SEND);
console.log($serviceURL);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doPost($params);
$responseLines = split("\n", $response);
$results = array();
foreach($responseLines as $responseLine) {
$responseLine = trim($responseLine);
if(empty($responseLine)) continue;
$result = array( 'error' => false, 'statusmessage' => '' );
if(preg_match("/ERR:(.*)/", trim($responseLine), $matches)) {
$result['error'] = true;
$result['to'] = $toNumbers[$i++];
$result['statusmessage'] = $matches[0]; // Complete error message
} else if(preg_match("/ID: ([^ ]+)TO:(.*)/", $responseLine, $matches)) {
$result['id'] = trim($matches[1]);
$result['to'] = trim($matches[2]);
$result['status'] = self::MSG_STATUS_PROCESSING;
} else if(preg_match("/ID: (.*)/", $responseLine, $matches)) {
$result['id'] = trim($matches[1]);
$result['to'] = $toNumbers[0];
$result['status'] = self::MSG_STATUS_PROCESSING;
}
$results[] = $result;
}
return $results;
}
/**
* Function to get query for status using messgae id
* @param <Number> $messageId
*/
public function query($messageId) {
$params = $this->prepareParameters();
$params['apimsgid'] = $messageId;
$serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doPost($params);
$response = trim($response);
$result = array( 'error' => false, 'needlookup' => 1 );
if(preg_match("/ERR: (.*)/", $response, $matches)) {
$result['error'] = true;
$result['needlookup'] = 0;
$result['statusmessage'] = $matches[0];
} else if(preg_match("/ID: ([^ ]+) Status: ([^ ]+)/", $response,
$matches)) {
$result['id'] = trim($matches[1]);
$status = trim($matches[2]);
// Capture the status code as message by default.
$result['statusmessage'] = "CODE: $status";
if($status === '1') {
$result['status'] = self::MSG_STATUS_PROCESSING;
} else if($status === '2') {
$result['status'] = self::MSG_STATUS_DISPATCHED;
$result['needlookup'] = 0;
}
}
return $result;
}
}
?>
Now, when i send sms by allowing Versatile as active sender, SMS not able to
produce.
Can anyone help me am I mistaken anywhere?
Thanks,
--
Sent from: http://vtiger-crm.2324883.n4.nabble.com/vtigercrm-developers-f4.html
More information about the vtigercrm-developers
mailing list