You are here

function sms_clickatell_receive_receipt in SMS Framework 6

Receive a message receipt from Clickatell

Will generate an $options array with the following variables: reference - A message reference code, if set on message send. Clickatell param: 'cliMsgId' receiver - The destination MSISDN number. Clickatell param: 'to' gateway_message_status - A Clickatell message status code. gateway_message_status_text - A text string associated with the gateway_status. For raw gateway params see Clickatell_HTTP.pdf page 10.

Note that there may be >1 receipt for a message that takes time to be delivered.

I have neglected the Clickatell 'timestamp' param because it is passed in non-UTC timezone and is in MySQL format. It is more useful to capture a timestamp in your hook_sms_receipt() function.

1 string reference to 'sms_clickatell_receive_receipt'
sms_clickatell_menu in modules/sms_clickatell/sms_clickatell.module
Implement hook_menu()

File

modules/sms_clickatell/sms_clickatell.module, line 434
Clickatell gateway module for Drupal SMS Framework. Outbound+Inbound+Receipts

Code

function sms_clickatell_receive_receipt() {
  $number = array_key_exists('from', $_REQUEST) ? $_REQUEST['from'] : NULL;
  $reference = array_key_exists('cliMsgId', $_REQUEST) ? $_REQUEST['cliMsgId'] : NULL;
  $gw_msg_status_code = array_key_exists('status', $_REQUEST) ? $_REQUEST['status'] : SMS_MSG_STATUS_UNKNOWN;
  $options = array();

  // Define raw gateway receipt call parameters
  $options['gateway_params'] = array();
  if (array_key_exists('to', $_REQUEST) && !empty($_REQUEST['to'])) {
    $options['gateway_params']['to'] = $_REQUEST['to'];
  }
  if (array_key_exists('api_id', $_REQUEST) && !empty($_REQUEST['api_id'])) {
    $options['gateway_params']['api_id'] = $_REQUEST['api_id'];
  }
  if (array_key_exists('moMsgId', $_REQUEST) && !empty($_REQUEST['moMsgId'])) {
    $options['gateway_params']['moMsgId'] = $_REQUEST['moMsgId'];
  }
  if (array_key_exists('charge', $_REQUEST) && !empty($_REQUEST['charge'])) {
    $options['gateway_params']['charge'] = $_REQUEST['charge'];
  }
  if (array_key_exists('cliMsgId', $_REQUEST) && !empty($_REQUEST['cliMsgId'])) {
    $options['gateway_params']['cliMsgId'] = $_REQUEST['cliMsgId'];
  }

  // Define message receiver and reference in options array
  $options['receiver'] = array_key_exists('to', $_REQUEST) ? $_REQUEST['to'] : '';
  $options['reference'] = $reference;

  // Get framework message status code and Clickatell status text
  $status = sms_clickatell_map_message_status_code($gw_msg_status_code);
  $gw_msg_status_codes = sms_clickatell_message_status_codes();
  $gw_msg_status_text = $gw_msg_status_codes[$gw_msg_status_code];

  // Define gateway-specific status (code) and text (success/error message)
  $options['gateway_message_status'] = $gw_msg_status_code;
  $options['gateway_message_status_text'] = $gw_msg_status_text;

  // Invoke the SMS Framework receipt handler
  sms_receipt($number, $reference, $status, $options);
}