HESK with SMS API function - script
Posted: Fri Apr 29, 2016 12:07 pm
Again, I'm a HESK fan, couple of installations, got this script developed a while ago and constantly need to search for it to update in new HESK updates.
PS: Hopefully I can use my same reference for future update reference
So I got this script developed by a Freelancer a couple of years ago that integrate with HESK and send the client a SMS (Text message) if he log a ticket online, or someone update his details with a valid cellphone number.
Currently using http://www.bulksms.com/ API function to send messages from Hesk.
Hope I post all the scripts again.
NOTE: You will have to modify the script for your own purposes.
NOTE: I used the custom field 4 in HESK to collect this mobile number.
NOTE: This will format number 082... to +278 automatically - international code for my country.
1. Add SMS function if the Admin replys to a ticket
admin\admin_reply_ticket.php (above line /* Add reply */)
//API Code: http://bulksms.2way.co.za:5567/eapi/sub ... 782xxxxxxx
$phone_number = trim($ticket['custom4']);
if (preg_match("/^0/", $phone_number)) {
$phone_number = preg_replace("/^0/", "+27", $phone_number);
}
if (strlen($phone_number) == 12) {
$text_message = "HESK responded to your ticket " . $ticket['trackid'] . ". Please check your emails for more detail.";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://bulksms.2way.co.za/eapi/submissi ... _sms/2/2.0");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=xxxxxx&password=xxxxxxx&message=" . $text_message . "&msisdn=" . $phone_number);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
}
2. Add the SMS function when the Admin submits a new ticket
admin\admin_submit_ticket.php (Above the line // Notify the customer about the ticket?)
//API Code: http://bulksms.2way.co.za:5567/eapi/sub ... 782xxxxxxx
$phone_number = trim($tmpvar['custom4']);
if (preg_match("/^0/", $phone_number)) {
$phone_number = preg_replace("/^0/", "+27", $phone_number);
}
if (strlen($phone_number) == 12) {
$text_message = "HESK received your ticket no. " . $ticket['trackid'] . ", check your email for updates.";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://bulksms.2way.co.za/eapi/submissi ... _sms/2/2.0");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=xxxxx&password=xxxxx&message=" . $text_message . "&msisdn=" . $phone_number);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
}
PS: Hopefully I can use my same reference for future update reference
So I got this script developed by a Freelancer a couple of years ago that integrate with HESK and send the client a SMS (Text message) if he log a ticket online, or someone update his details with a valid cellphone number.
Currently using http://www.bulksms.com/ API function to send messages from Hesk.


NOTE: You will have to modify the script for your own purposes.
NOTE: I used the custom field 4 in HESK to collect this mobile number.
NOTE: This will format number 082... to +278 automatically - international code for my country.
1. Add SMS function if the Admin replys to a ticket
admin\admin_reply_ticket.php (above line /* Add reply */)
//API Code: http://bulksms.2way.co.za:5567/eapi/sub ... 782xxxxxxx
$phone_number = trim($ticket['custom4']);
if (preg_match("/^0/", $phone_number)) {
$phone_number = preg_replace("/^0/", "+27", $phone_number);
}
if (strlen($phone_number) == 12) {
$text_message = "HESK responded to your ticket " . $ticket['trackid'] . ". Please check your emails for more detail.";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://bulksms.2way.co.za/eapi/submissi ... _sms/2/2.0");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=xxxxxx&password=xxxxxxx&message=" . $text_message . "&msisdn=" . $phone_number);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
}
2. Add the SMS function when the Admin submits a new ticket
admin\admin_submit_ticket.php (Above the line // Notify the customer about the ticket?)
//API Code: http://bulksms.2way.co.za:5567/eapi/sub ... 782xxxxxxx
$phone_number = trim($tmpvar['custom4']);
if (preg_match("/^0/", $phone_number)) {
$phone_number = preg_replace("/^0/", "+27", $phone_number);
}
if (strlen($phone_number) == 12) {
$text_message = "HESK received your ticket no. " . $ticket['trackid'] . ", check your email for updates.";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://bulksms.2way.co.za/eapi/submissi ... _sms/2/2.0");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=xxxxx&password=xxxxx&message=" . $text_message . "&msisdn=" . $phone_number);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
}