[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/twilio-php/Services/Twilio/Rest/ -> Messages.php (source)

   1  <?php
   2  
   3  class Services_Twilio_Rest_Messages extends Services_Twilio_ListResource {
   4  
   5      /**
   6       * Create a new Message instance
   7       *
   8       * Example usage:
   9       *
  10       * .. code-block:: php
  11       *
  12       *      $client->account->messages->create(array(
  13       *          "Body" => "foo",
  14       *          "From" => "+14105551234",
  15       *          "To" => "+14105556789",
  16       *      ));
  17       *
  18       * :param array $params: a single array of parameters which is serialized and
  19       *      sent directly to the Twilio API. You may find it easier to use the
  20       *      sendMessage helper instead of this function.
  21       *
  22       */
  23      public function create($params = array()) {
  24          return parent::_create($params);
  25      }
  26  
  27      /**
  28       * Send a message
  29       *
  30       * .. code-block:: php
  31       *
  32       *      $client = new Services_Twilio('AC123', '123');
  33       *      $message = $client->account->messages->sendMessage(
  34       *          '+14105551234', // From a Twilio number in your account
  35       *          '+14105556789', // Text any number
  36       *          'Come at the king, you best not miss.'   // Message body (if any)
  37       *          array('https://demo.twilio.com/owl.png'),   // An array of MediaUrls
  38       *      );
  39       *
  40       * :param string $from: the from number for the message, this must be a
  41       *      number you purchased from Twilio
  42       * :param string $to: the message recipient's phone number
  43       * :param $mediaUrls: the URLs of images to send in this MMS
  44       * :type $mediaUrls: null (don't include media), a single URL, or an array
  45       *      of URLs to send as media with this message
  46       * :param string $body: the text to include along with this MMS
  47       * :param array $params: Any additional params (callback, etc) you'd like to
  48       *      send with this request, these are serialized and sent as POST
  49       *      parameters
  50       *
  51       * :return: The created :class:`Services_Twilio_Rest_Message`
  52       * :raises: :class:`Services_Twilio_RestException`
  53       *      An exception if the parameters are invalid (for example, the from
  54       *      number is not a Twilio number registered to your account, or is
  55       *      unable to send MMS)
  56       */
  57      public function sendMessage($from, $to, $body = null, $mediaUrls = null,
  58          $params = array()
  59      ) {
  60          $postParams = array(
  61              'From' => $from,
  62              'To' => $to,
  63          );
  64          // When the request is made, this will get serialized into MediaUrl=a&MediaUrl=b
  65          if (!is_null($mediaUrls)) {
  66              $postParams['MediaUrl'] = $mediaUrls;
  67          }
  68          if (!is_null($body)) {
  69              $postParams['Body'] = $body;
  70          }
  71          return self::create($postParams + $params);
  72      }
  73  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1