diff --git a/externals/twilio-php b/externals/twilio-php new file mode 160000 --- /dev/null +++ b/externals/twilio-php @@ -0,0 +1 @@ +Subproject commit 389e07ee41eabc422ea88b805006bccac7de9eb3 diff --git a/src/infrastructure/sms/adapter/PhabricatorSMSImplementationAdapter.php b/src/infrastructure/sms/adapter/PhabricatorSMSImplementationAdapter.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/sms/adapter/PhabricatorSMSImplementationAdapter.php @@ -0,0 +1,63 @@ +fromNumber = $number; + return $this; + } + + public function getFrom() { + return $this->fromNumber; + } + + public function setTo($number) { + $this->toNumber = $number; + return $this; + } + + public function getTo() { + return $this->toNumber; + } + + public function setBody($body) { + $this->body = $body; + return $this; + } + + public function getBody() { + return $this->body; + } + + /** + * Send the message. Generally, this means connecting to some service and + * handing data to it. + * + * If the adapter determines that the SMS will never be deliverable, it + * should throw an exception. + * + * For temporary failures, throw some other exception or return `false`. + * + * @return bool True on success. + */ + abstract public function send(); + + /** + * Convenience function to handling sending an SMS. + */ + public static function sendSMS(array $to_numbers, $body) { + $adapter = PhabricatorEnv::getEnvConfig('sms.default-adapter'); + $from_number = PhabricatorEnv::getEnvConfig('sms.default-sender'); + PhabricatorWorker::scheduleTask( + 'PhabricatorSMSDemultiplexer', + array( + 'fromNumber' => $from_number, + 'toNumbers' => $to_numbers, + 'body' => $body, + 'adapter' => $adapter)); + } +} diff --git a/src/infrastructure/sms/adapter/PhabricatorSMSImplementationTwilioAdapter.php b/src/infrastructure/sms/adapter/PhabricatorSMSImplementationTwilioAdapter.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/sms/adapter/PhabricatorSMSImplementationTwilioAdapter.php @@ -0,0 +1,20 @@ +account->sms_messages->create(array( + 'From' => $this->getFrom(), + 'To' => $this->getTo(), + 'Body' => $this->getBody())); + } +} diff --git a/src/infrastructure/sms/storage/PhabricatorSMS.php b/src/infrastructure/sms/storage/PhabricatorSMS.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/sms/storage/PhabricatorSMS.php @@ -0,0 +1,17 @@ +getTaskData(); + + $to_numbers = idx($task_data, 'toNumbers'); + if (!$to_numbers) { + // If we don't have any to numbers, don't send any sms. + return; + } + + foreach ($to_numbers as $number) { + $this->queueTask( + 'PhabricatorSMSSendWorker', + array( + 'fromNumber' => $task_data['from_number'], + 'toNumber' => $number, + 'body' => $task_data['body'], + 'adapter' => $task_data['adapter'])); + } + } + +} diff --git a/src/infrastructure/sms/worker/PhabricatorSMSSendWorker.php b/src/infrastructure/sms/worker/PhabricatorSMSSendWorker.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/sms/worker/PhabricatorSMSSendWorker.php @@ -0,0 +1,18 @@ +getTaskData(); + + $adapter = newv($task_data['adapter'], array()); + $adapter->setTo($task_data['toNumber']); + $adapter->setFrom($task_data['fromNumber']); + $adapter->setBody($task_data['body']); + $adapter->send(); + } + +} diff --git a/src/infrastructure/sms/worker/PhabricatorSMSWorker.php b/src/infrastructure/sms/worker/PhabricatorSMSWorker.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/sms/worker/PhabricatorSMSWorker.php @@ -0,0 +1,11 @@ +