Created
January 31, 2017 08:15
-
-
Save JaniKibichi/a45c91e98102e1c9e38828e7ae18846b to your computer and use it in GitHub Desktop.
A callback code for Handling MT Shortcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(‘DBConn.php’); //this is your Database connection information, where you also abstract $apiUsername, $apikey | |
require_once(‘AfricasTalkingGateway.php’); | |
//next we receive notification from API | |
//and read in post params to our variables | |
$apiUsername =’XXXXX’; | |
$apikey =’kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk’; | |
if($_POST) | |
{ | |
$number = $POST_['phoneNumber']; | |
$shortcode = $_POST['shortCode']; | |
$keyword = $_POST['keyword']; | |
$updateType = $POST_['updateType']; | |
/* | |
$number = ‘+254721748323′; | |
$shortcode = ’22384′; | |
$text = ‘love‘; | |
$updateType = ‘Addition’; | |
*/ | |
if($updateType==’Addition’) | |
{ | |
//Create a SQL query | |
//persist in db | |
//invoke sendMessage and try to send | |
$recipients = $number; | |
$message = “You are my love”; | |
$gateway = new AfricasTalkingGateway($apiUsername, $apikey); | |
try | |
{ | |
$from = ’22384′; | |
$bulkSmsMode = ’0′; | |
$params = array(); | |
$params['keyword'] = ‘Love’; | |
// Thats it, hit send and we’ll take care of the rest. | |
$results = $gateway->sendMessage($recipients, $message,$from,$bulkSmsMode,$params); | |
foreach($results as $result) | |
{ | |
$messageId = $result->messageId; | |
$status = $result->status; | |
//persist in outbox | |
} | |
} | |
catch ( AfricasTalkingGatewayException $e ) | |
{ | |
//echo “Encountered an error while sending: “.$e->getMessage(); | |
error_log $e->getMessage(); | |
} | |
################################# | |
//exit | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment