SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Tue Apr 16, 2024 12:54
SMSTools3 Community » Help and support Bottom

[solved] CRM Intergration

  This topic is locked

Page:  1

Author Post
Member
Registered:
Feb 2011
Location: New Delhi, India
Operating system name and version: Debain Lenny 5
Version of smsd: 3.1.14
Smsd installed from: sources / package repository / from elsewhere...
Name and model of a modem / phone: Teltonika E 12 / Itegno 3800
Interface: USB

Dear Sir,

I am using Vtiger CRM which has a feature for Sending SMS using Clickatell Gateway.

I am wondering, if my SMStools3 & PlaySMS installation can be used as SMS Gateway

Following is the Code used for to send SMS through Clickatell or Any SMS Gateway


<?php
/*+**********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/

include_once dirname(__FILE__) . '/../ISMSProvider.php';
include_once 'vtlib/Vtiger/Net/Client.php';

class ClickATell implements ISMSProvider {
       
        private $_username;
        private $_password;
        private $_parameters = array();
       
        const SERVICE_URI = 'http://api.clickatell.com';
        private static $REQUIRED_PARAMETERS = array('api_id');
       
        function __construct() {               
        }
       
        public function setAuthParameters($username, $password) {
                $this->_username = $username;
                $this->_password = $password;
        }
       
        public function setParameter($key, $value) {
                $this->_parameters[$key] = $value;
        }
       
        public function getParameter($key, $defvalue = false)  {
                if(isset($this->_parameters[$key])) {
                        return $this->_parameters[$key];
                }
                return $defvalue;
        }
       
        public function getRequiredParams() {
                return self::$REQUIRED_PARAMETERS;
        }
       
        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 . '/http/sendmsg';
                                case self::SERVICE_QUERY: return self::SERVICE_URI . '/http/querymsg';                 
                        }
                }
                return false;
        }      
       
        public function send($message, $tonumbers) {
                if(!is_array($tonumbers)) {
                        $tonumbers = array($tonumbers);
                }
                $serviceURL = $this->getServiceURL(self::SERVICE_SEND);

                $httpClient = new Vtiger_Net_Client($serviceURL);
                $response = $httpClient->doPost(array(
                        'user' => $this->_username,
                        'password' => $this->_password,
                        'api_id' => $this->getParameter('api_id'),
                       
                        'text' => $message,
                        'to'   => implode(',', $tonumbers)
                ));
                $responseLines = split("\n", $response);               

                $results = array();
                $i=0;
                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;
        }
       
        public function query($messageid) {

                $serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
                $httpClient = new Vtiger_Net_Client($serviceURL);
                $response = $httpClient->doPost(array(
                        'user' => $this->_username,
                        'password'  => $this->_password,
                        'api_id' => $this->getParameter('api_id'),             
                        'apimsgid' => $messageid
                ));
               
                $response = trim($response);

                $result = array( 'error' => false, 'needlookup' => 1, 'statusmessage' => '' );
               
                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 == '002' || $status == '008' || $status == '011' ) {
                                $result['status'] = self::MSG_STATUS_PROCESSING;
                        } else if($status == '003' || $status == '004') {
                                $result['status'] = self::MSG_STATUS_DISPATCHED;
                                $result['needlookup'] = 0;
                        } else {
                                $statusMessage = "";
                                switch($status) {
                                case '001': $statusMessage = 'Message unknown';                 $needlookup = 0; break;
                                case '005': $statusMessage = 'Error with message';              $needlookup = 0; break;
                                case '006': $statusMessage = 'User cancelled message delivery'; $needlookup = 0; break;
                                case '007': $statusMessage = 'Error delivering message';        $needlookup = 0; break;
                                case '009': $statusMessage = 'Routing error';                   $needlookup = 0; break;
                                case '010': $statusMessage = 'Message expired';                 $needlookup = 0; break;
                                case '012': $statusMessage = 'Out of credit';                   $needlookup = 0; break;
                                }                      
                                if(!empty($statusMessage)) {           
                                        $result['error'] = true;
                                        $result['needlookup'] = $needlookup;
                                        $result['statusmessage'] = $statusmessage;
                                }
                        }
                }      
                return $result;
        }
}
?>
 
 
'php' Syntax Highlight powered by GeSHi


Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Everything can be done ;).

Just modify the script: instead of calling Clickatell API, create a SMS file into the /var/spool/sms/outgoing directory, and return the result which means "message is successfully sent". Sending thru PlaySMS is little bit more complicated, as you need to post the data to the PlaySMS.

Member
Registered:
Feb 2011
Location: New Delhi, India
Topic owner
Dear Sir,

Thank you for your reply.

Could you please advice on implementation procedure with some sample script.

Further, our CRM Vtiger installation is hosted on another web server & SMStools3with PlaySMS is on another web server having Static IP

Thanks & regards,

Tummy

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
tummyg wrote
Could you please advice on implementation procedure with some sample script.

Further, our CRM Vtiger installation is hosted on another web server & SMStools3with PlaySMS is on another web server having Static IP

Put this kind of a script into your web server, and call it from the CRM:

<?php

$application = "web-send-sms";
$outgoing = "/var/spool/sms/outgoing";
$error = 0;

if (empty($_GET['To']) || empty($_GET['Message']))
  $error = 1;
else
{
  $dests = split(',', $_GET['To']);
  $message = stripslashes($_GET['Message']);

  foreach ($dests as $dest)
  {
    $filename = $outgoing ."/". $application ."-" .str_replace(".", "", uniqid(mt_rand(), true));
    if (($handle = fopen($filename .".LOCK", "w")) != false)
    {
      fwrite($handle, "To: " .trim($dest) ."\n");
      fwrite($handle, "Application: " .$application ."\n");
      fwrite($handle, "\n");
      fwrite($handle, $message);
      fclose($handle);

      if (rename($filename .".LOCK", $filename) != true)
      {
        $error = 3;
        break;
      }
    }
    else
    {
      $error = 2;
      break;
    }
  }
}

if (!$error)
  print "OK.";
else
  print "ERROR " .$error .".";
?>
 
 
'php' Syntax Highlight powered by GeSHi


Member
Registered:
Feb 2011
Location: New Delhi, India
Topic owner
Dear Sir,

Thank you for Sample Script, which I tried pushing through my Vtiger Installation(Hosted on Different Server) to SMStools3 gateway which is on my Server at my location but could not work.


As far as I understand, Vtiger CRM pushs SMS through API to SMS Gateway. Could you please advice on the issue to pushing through API to smstools3

Thanks & regards,

Tummy

Member
Registered:
Feb 2011
Location: New Delhi, India
Topic owner
Hello all,

Can anyone help me on my API post

Thanks & regards

Member
Registered:
Feb 2011
Location: New Delhi, India
Topic owner
Hi,

I have done this & now I can send SMS from my Vtiger Installation.

I used the following to solve my problem

WEBSERVICES ACCESS
------------------
URL: http://[playSMS_web_domain_or_url]/index.php?app=webservices


PARAMETERS
----------
u : username
p : password

ta : type of action
for example:
pv : send private
bc : send broadcast
ds : delivery status
sms_poll : poll results from plugin sms_poll
sms_board : board results from plugin sms_board

to : destination number (for ta=pv) or destination group code (for ta=bc)
msg : message
type : message type (1=flash, 2=text)
unicode : whether message unicode or not (1=unicode, 0=not unicode)

last : last SMS log ID (this number not included on result)
c : number of delivery status that will be retrieved
slid : SMS Log ID (for ta=ds, when slid defined 'last' and 'c' has no effect)

Thanks

Tummy

  This topic is locked

Page:  1

SMSTools3 Community » Help and support Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.