Results 1 to 2 of 2

Thread: SMS with Clickatell

  1. #1
    thamima is offline Senior Member
    Join Date
    Mar 2009
    Location
    Pretoria, South Africa
    Posts
    23

    Question SMS with Clickatell

    Can someone please take a look at this and tell me where I'm going wrong. I'm trying to create a custom module to send sms using Clickatell and I've added a logic hook on before_save to add the code for sending the message before saving so that I can save the message id from the sms gateway. The Problem is it seems to skip the part for sending the sms and retrieving response from sms gateway. The is the the logic hook I'm trying to fire:

    logic_hooks.php
    Code:
    <?php
    $hook_version = 1;
    $hook_array = Array();
    // position, file, class, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'before_save', 'custom/modules/sms/SendSMS.php','SendSMS', 'SendSMS');
    ?>
    SendSMS.php
    Code:
    <?php
    	if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
     	require_once('data/SugarBean.php');
    	require_once('modules/sms/sms.php');
    	require_once('include/utils.php');
    	require_once('custom/modules/sms/settings.php');
    	
    	
    	class SendSMS {
    		function GetSQLValueString($theValue) {
    	  		$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    	  		return $theValue;
    		}
    		function SendSMS(&$bean, $event, $arguments){
    			$sender = 'GEP';
    			$parent = $bean->parent_id;
    			$message = $bean->sms_msg;
    			if ($bean->cell_no != '') {
    				$to = $bean->cell_no;
    			} else
    				if ($bean->parent_type == 'Leads') {
    					$query = 'SELECT phone_mobile from leads where id = $parent';
    				} elseif ($bean->parent_type == 'Contacts') {
    					$query = 'SELECT phone_mobile from contacts where id = $parent';
    				} elseif ($bean->parent_type == 'Accounts') {
    					$query = 'SELECT phone_alternate as phone_mobile from accounts where id = $parent';
    				} elseif ($bean->parent_type == 'sp_ServiceProvider') {
    					$query = 'SELECT phone_alternate as phone_mobile from sp_serviceprovider where id = $parent';
    				}
    				$result = $GLOBALS['db']->query($query); 
    				$row = $GLOBALS['db']->fetchByAssoc($result);
    				if($row != null) {
    					$to = $row_result['phone_mobile'];
    				} 
    				//get magic quotes
    				$message = GetSQLValueString($message);
    				
    				//url encode message
    				$message = urlencode($message);
    				
    				//authenticating user
    				$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id&from=$from&concat=2";
    				$ret = file($url);
    				
    				// split our response. return string is on first line of the data returned
    				$sess = split(":",$ret[0]);
    				if ($sess[0] == "OK") {
    					$sess_id = trim($sess[1]); // remove any whitespace
    
    					// url for sending message
    					$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$message&from=$from&callback=3&deliv_ack=1&concat=2";
    				
    					// send message
    					$ret = file($url);
    					$send = split(":",$ret[0]);
    					if ($send[0] == "ID"){
    						// apimsgid
    						$apimsgid = trim($send[1]);
    						// insert message with its corresponding apimsgid into the table
    						$bean->apimsgid = $apimsgid;
    						$bean->status = 'sent';
    					} else
    						$bean->apimsgid = $apimsgid;
    						$bean->status = 'failed';
    					} 
    				}
    			} 
    			
    ?>
    and the settings.php
    Code:
    <?php
    
    $baseurl ="http://api.clickatell.com";
    
    //User details @ CLickatell
    $user = "xyz";
    $password = "password";
    $api_id = "xxxxxx";
    ?>
    Please help

  2. #2
    chinwoei's Avatar
    chinwoei is offline Sugar Community Member
    Join Date
    Jul 2007
    Posts
    91

    Default Re: SMS with Clickatell

    Quote Originally Posted by thamima View Post
    Can someone please take a look at this and tell me where I'm going wrong. I'm trying to create a custom module to send sms using Clickatell and I've added a logic hook on before_save to add the code for sending the message before saving so that I can save the message id from the sms gateway. The Problem is it seems to skip the part for sending the sms and retrieving response from sms gateway. The is the the logic hook I'm trying to fire:

    logic_hooks.php
    Code:
    <?php
    $hook_version = 1;
    $hook_array = Array();
    // position, file, class, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'before_save', 'custom/modules/sms/SendSMS.php','SendSMS', 'SendSMS');
    ?>
    SendSMS.php
    Code:
    <?php
    	if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
     	require_once('data/SugarBean.php');
    	require_once('modules/sms/sms.php');
    	require_once('include/utils.php');
    	require_once('custom/modules/sms/settings.php');
    	
    	
    	class SendSMS {
    		function GetSQLValueString($theValue) {
    	  		$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    	  		return $theValue;
    		}
    		function SendSMS(&$bean, $event, $arguments){
    			$sender = 'GEP';
    			$parent = $bean->parent_id;
    			$message = $bean->sms_msg;
    			if ($bean->cell_no != '') {
    				$to = $bean->cell_no;
    			} else
    				if ($bean->parent_type == 'Leads') {
    					$query = 'SELECT phone_mobile from leads where id = $parent';
    				} elseif ($bean->parent_type == 'Contacts') {
    					$query = 'SELECT phone_mobile from contacts where id = $parent';
    				} elseif ($bean->parent_type == 'Accounts') {
    					$query = 'SELECT phone_alternate as phone_mobile from accounts where id = $parent';
    				} elseif ($bean->parent_type == 'sp_ServiceProvider') {
    					$query = 'SELECT phone_alternate as phone_mobile from sp_serviceprovider where id = $parent';
    				}
    				$result = $GLOBALS['db']->query($query); 
    				$row = $GLOBALS['db']->fetchByAssoc($result);
    				if($row != null) {
    					$to = $row_result['phone_mobile'];
    				} 
    				//get magic quotes
    				$message = GetSQLValueString($message);
    				
    				//url encode message
    				$message = urlencode($message);
    				
    				//authenticating user
    				$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id&from=$from&concat=2";
    				$ret = file($url);
    				
    				// split our response. return string is on first line of the data returned
    				$sess = split(":",$ret[0]);
    				if ($sess[0] == "OK") {
    					$sess_id = trim($sess[1]); // remove any whitespace
    
    					// url for sending message
    					$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$message&from=$from&callback=3&deliv_ack=1&concat=2";
    				
    					// send message
    					$ret = file($url);
    					$send = split(":",$ret[0]);
    					if ($send[0] == "ID"){
    						// apimsgid
    						$apimsgid = trim($send[1]);
    						// insert message with its corresponding apimsgid into the table
    						$bean->apimsgid = $apimsgid;
    						$bean->status = 'sent';
    					} else
    						$bean->apimsgid = $apimsgid;
    						$bean->status = 'failed';
    					} 
    				}
    			} 
    			
    ?>
    and the settings.php
    Code:
    <?php
    
    $baseurl ="http://api.clickatell.com";
    
    //User details @ CLickatell
    $user = "xyz";
    $password = "password";
    $api_id = "xxxxxx";
    ?>
    Please help
    Hi Thamima,

    Check out our sms module, it might be fulfill your requirement.
    http://www.sugarforge.org/projects/izeno-sms/
    I am from iZeno Pte Ltd
    Personal Site: Technical Sharing
    SugarForge Project:
    iZeno SMS : http://www.sugarforge.org/projects/izeno-sms/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •