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)
Thu, Apr 11, 10:38 AM
Unknown Object (File)
Wed, Apr 10, 4:23 PM
Unknown Object (File)
Tue, Apr 2, 6:41 PM
Unknown Object (File)
Thu, Mar 21, 11:06 PM
Unknown Object (File)
Mar 15 2024, 12:04 PM
Unknown Object (File)
Feb 24 2024, 4:14 PM
Unknown Object (File)
Jan 23 2024, 4:59 PM
Unknown Object (File)
Jan 16 2024, 11:55 AM
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.