Page MenuHomePhabricator

Add a Twilio SMS message adapter
ClosedPublic

Authored by epriestley on Jan 14 2019, 9:55 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Aug 8, 10:40 AM
Unknown Object (File)
Thu, Aug 4, 11:16 AM
Unknown Object (File)
Tue, Jul 26, 10:29 PM
Unknown Object (File)
Jul 12 2022, 11:16 AM
Unknown Object (File)
Jul 10 2022, 6:36 AM
Unknown Object (File)
Jul 4 2022, 6:32 PM
Unknown Object (File)
Jun 14 2022, 9:39 PM
Unknown Object (File)
Jun 11 2022, 6:26 PM
Subscribers
None

Details

Summary

Ref T920. Adds a "phone number" object, an "SMS" message type, and Twilio glue.

Test Plan

Used this test script to send myself some text messages after configuring Twilio in cluster.mailers.

<?php

require_once 'scripts/init/init-script.php';

if ($argc < 3) {
  throw new Exception('usage: test.php <number> <body>');
}
$to_number = $argv[1];
$text_body = $argv[2];

$mailers = PhabricatorMetaMTAMail::newMailers(
  array(
    'outbound' => true,
    'media' => array(
      PhabricatorMailSMSMessage::MESSAGETYPE,
    ),
  ));
if (!$mailers) {
  return new Aphront404Response();
}
$mailer = head($mailers);

$message = id(new PhabricatorMailSMSMessage())
  ->setToNumber(new PhabricatorPhoneNumber($to_number))
  ->setTextBody($text_body);

$mailer->sendMessage($message);

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

src/applications/metamta/adapter/PhabricatorMailTwilioAdapter.php
4

You should be able to add a similar class to this for AWS SNS now (well, once all this stuff lands), I think.

amckinley added inline comments.
src/applications/metamta/message/PhabricatorPhoneNumber.php
12

Where did this regex come from? A few minutes of digging for validating of E.123 numbers points to this O'Reilly suggestion: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s03.html

This revision is now accepted and ready to land.Jan 16 2019, 2:08 AM
src/applications/metamta/message/PhabricatorPhoneNumber.php
12

I expect this will be refined a lot, but it's more-or-less from the Twilio docs here:

https://www.twilio.com/docs/glossary/what-e164

Used this test script to send myself some text messages...

Why not use this to resurrect bin/sms?

The script is currently very bare-metal since PhabricatorMetaMTAMail doesn't actually have the "this might be an SMS" code yet.

That chunk of code is up relatively-soon-ish but I expect it will mean that bin/mail send-test gets a --medium sms or something rather than a separate bin/sms / bin/apns / bin/whatsapp set of entrypoints. I'll see how much of a mess that is, I might resurrect bin/sms if the flags are too confusing (or bin/mail send-short-message-like-sms-or-whatsapp or something). But the "action" bit at the end should be $mail->send(), not $mailer->sendMessage(...).

Doing $mail->send() means that we get retries, a listing in bin/mail list-outbound, an entry in /mail/, non-delivery to disabled users, and a bunch of other support infrastructure stuff.

This revision was automatically updated to reflect the committed changes.