Senin, 14 Maret 2016

Auto Replay with Filtering By Kalkun + Gammu


Langsung saja tanpa basa basi :

Tambahkan Code berikut kedalam kalkun_settings.php


$config['sms_filtered'] = TRUE; $config['sms_filtered_keyword'] = array('minang','minangkabau','kota,'padang','sumbar'); $config['sms_filtered_msg'] = 'Nama Minangkabau berasal dari dua kata, minang dan kabau';

lalu tambahkan code berikut kedalam daemon.php

function _sms_filtered($phone_number,$TextDecoded)
{
$data['coding'] = 'default';
$data['class'] = '1';
$data['dest'] = $phone_number;
$data['smsdata'] = $TextDecoded;
$data['date'] = date('Y-m-d H:i:s');
$data['message'] = $this->config->item('sms_filtered_msg');
$data['keyword'] = $this->config->item('sms_filtered_keyword');
$data['delivery_report'] = 'default';
$this->Message_model->send_filtered_msg($data);
 kemudian tambahkan fungsi berikut kedalam message_model.php

function send_filtered_msg($data)
{         if($this->config->item('disable_outgoing'))
        {
            echo "<div class=\"notif\">Outgoing SMS Disabled</div>"; return;
        }
$keyword_found = false;
foreach($data['keyword'] as $keyword){
if(preg_match('/\b'.$keyword.'\b/i', $data['smsdata'])){
$keyword_found = true;break;
}else{
$keyword_found = false;
}
}
        if($data['dest']!=NULL && $data['date']!=NULL && $data['smsdata']!=NULL && $keyword_found && $data['dest'] != '+6281933536231')
{
$messagelength = strlen($data['message']);
switch($data['coding'])
{
case 'default':
$standar_length = 160;
$data['coding'] = 'Default_No_Compression';
break;
case 'unicode':
$standar_length = 70;
$data['coding'] = 'Unicode_No_Compression';
break;
}
$UDH_length = 7;
$multipart_length = $standar_length - $UDH_length;
if($messagelength > $standar_length)
{
$UDH = "050003";
$UDH .= strtoupper(dechex(mt_rand(0, 255)));
$data['UDH'] = $UDH;
$tmpmsg = str_split($data['message'], $multipart_length);
$part = count($tmpmsg);
if($part < 10) $part = '0'.$part;
$data['option'] = 'multipart';
$data['message'] = $tmpmsg[0];
$data['part'] = $part;
$outboxid = $this->_send_message_route($data);
                $this->Kalkun_model->add_sms_used($this->session->userdata('id_user')); for($i=1; $i<count($tmpmsg); $i++)
{
   $this->_send_message_multipart($outboxid, $tmpmsg[$i], $i, $part, $data['coding'], $data['class'], $UDH);
                    $this->Kalkun_model->add_sms_used($this->session->userdata('id_user'));                 }
} else
{
$data['option'] = 'single';
$this->_send_message_route($data);
$this->Kalkun_model->add_sms_used($this->session->userdata('id_user')); } }
}
 lalu pada daemon.php ganti fungsi message_routine menjadi seperti pada code berikut ini :function message_routine()

function message_routine()
{
$this->load->model('User_model');$this->load->library('session');
$message = $this->Message_model->get_messages(array('processed' => FALSE));
foreach($message->result() as $tmp_message)
{ if($this->config->item('sms_content'))
{
$this->_sms_content($tmp_message->TextDecoded, $tmp_message->SenderNumber);
} $users = $this->User_model->getUsers(array('option' => 'all'));
foreach($users->result() as $tmp_user)
{
$tag = "@".$tmp_user->username;
$msg_word = array();
$msg_word = explode(" ", $tmp_message->TextDecoded);
$check = in_array($tag, $msg_word);
if($check!==false) { $this->Message_model->update_owner($tmp_message->ID, $tmp_user->id_user); $msg_user =  $tmp_user->id_user;  break; }
}
if($check===false){ $this->Message_model->update_owner($tmp_message->ID, $this->config->item('inbox_owner_id'));  $msg_user =  $this->config->item('inbox_owner_id');  }
if($this->config->item('simple_autoreply'))
{
$this->_simple_autoreply($tmp_message->SenderNumber); } if($this->config->item('sms_filtered'))
{
$this->_sms_filtered($tmp_message->SenderNumber,$tmp_message->TextDecoded); } if($this->config->item('ext_script_state'))
{
$this->_external_script($tmp_message->SenderNumber, $tmp_message->TextDecoded, $tmp_message->ID); } $id_message[0] = $tmp_message->ID;
$multipart = array('type' => 'inbox', 'option' => 'check', 'id_message' => $id_message[0]);
$tmp_check = $this->Message_model->get_multipart($multipart);
if($tmp_check->row('UDH')!='')
{
$multipart = array('option' => 'all', 'udh' => substr($tmp_check->row('UDH'),0,8)); $multipart['phone_number'] = $tmp_check->row('SenderNumber');
$multipart['type'] = 'inbox'; foreach($this->Message_model->get_multipart($multipart)->result() as $part):
$id_message[] = $part->ID;
endforeach; }             $this->Message_model->update_processed($id_message);
$this->_sms2email($tmp_message->TextDecoded, $tmp_message->SenderNumber , $msg_user);
           
} }
Jika sudah silahkan coba runingkan lalu tes sms ke pada server dengan isi sms "padang" jika anda mendapatkan replay "Nama Minangkabau berasal dari dua kata, minang dan kabau".  maka fitur filter auto replay pada kalkun sudah siap.