Path: blob/master/src/applications/metamta/adapter/PhabricatorMailTwilioAdapter.php
12256 views
<?php12final class PhabricatorMailTwilioAdapter3extends PhabricatorMailAdapter {45const ADAPTERTYPE = 'twilio';67public function getSupportedMessageTypes() {8return array(9PhabricatorMailSMSMessage::MESSAGETYPE,10);11}1213protected function validateOptions(array $options) {14PhutilTypeSpec::checkMap(15$options,16array(17'account-sid' => 'string',18'auth-token' => 'string',19'from-number' => 'string',20));2122// Construct an object from the "from-number" to validate it.23$number = new PhabricatorPhoneNumber($options['from-number']);24}2526public function newDefaultOptions() {27return array(28'account-sid' => null,29'auth-token' => null,30'from-number' => null,31);32}3334public function sendMessage(PhabricatorMailExternalMessage $message) {35$account_sid = $this->getOption('account-sid');3637$auth_token = $this->getOption('auth-token');38$auth_token = new PhutilOpaqueEnvelope($auth_token);3940$from_number = $this->getOption('from-number');41$from_number = new PhabricatorPhoneNumber($from_number);4243$to_number = $message->getToNumber();44$text_body = $message->getTextBody();4546$parameters = array(47'From' => $from_number->toE164(),48'To' => $to_number->toE164(),49'Body' => $text_body,50);5152$result = id(new PhabricatorTwilioFuture())53->setAccountSID($account_sid)54->setAuthToken($auth_token)55->setMethod('Messages.json', $parameters)56->setTimeout(60)57->resolve();58}5960}616263