You are here

function twilio_tokens in Twilio 7

Implements hook_tokens().

File

./twilio.module, line 422
Twilio module

Code

function twilio_tokens($type, $tokens, array $data = array(), array $options = array()) {

  // SMS tokens.
  if ($type == 'sms' && !empty($data['sms'])) {
    $sms = $data['sms'];
    $replacements = array();
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'number':
          $replacements[$original] = $sms['number'];
          break;
        case 'number_twilio':
          $replacements[$original] = $sms['number_twilio'];
          break;
        case 'message':
          $replacements[$original] = $sms['message'];
          break;
        case 'media':
          $replacements[$original] = $sms['media'];
          break;
      }
    }
    return $replacements;
  }

  // Voice call tokens.
  if ($type == 'voice' && !empty($data['voice'])) {
    $voice = $data['voice'];
    $replacements = array();
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'number':
          $replacements[$original] = $voice['number'];
          break;
        case 'number_twilio':
          $replacements[$original] = $voice['number_twilio'];
          break;
      }
    }
    return $replacements;
  }
}