Robocalling in 12 minutes*
On John Oliver's Last Week Tonight, he showed how they were robocalling the FCC commissioners. As an offhanded comment he said their tech person literally got it running in less than 15 minutes. I took that as a challenge, and based on a comment from Kirsten, my goal was to get audio of our Audreycat growling when she answered the phone.
I was confident because I knew I had an account ready to go at Twilio. They have developer-friendly APIs and I had previous experience of managing over 10k phone numbers on their platform, though I hadn't done it recently.
So, I bought a phone number from an area code she'd recognize and cobbled together the code from their sample:
from twilio.rest import Client k = "+15035551212" phone="+13095551212" acct_sid="xx" acct_tok="yy" client = Client(acct_sid,acct_tok) call = client.calls.create( url='https://tedder.me/twilio/hi3.xml', to=k, from_=phone ) print(call.sid)
And here's the XML, which tells Twilio what to do after the phone is picked up, which I put on S3:
<?xml version="1.0" encoding="UTF-8"?> <Response> <Say voice="alice">hi kirsten</Say> <Play>https://tedder.me/twilio/audrey.mp3</Play> </Response>
Sure enough, I had her phone ringing 12 minutes later. She picked up, and a robot voice told her there was an error. What?!
So, I did it in 12 minutes, but it took another 13 minutes to figure out what was wrong. Twilio's error console said it was returning a 403 error, which didn't make sense, as I could access the content just fine.
With some further digging I found that the XML URL is hit with
POST, so I knew the problem- the content was being served from S3, which only expects a
GET. So I had to dig further to find all of the parameters to the Twilio code. It was actually really hard to find good documentation for the python library, as everything pointed to the basics of using the library. Finally I found the entrypoint to the documentation, and after a lot of work I got to the
calls.create documentation. It was difficult to find but the answer was easy- I needed to add a parameter called
call = client.calls.create( method='GET', url='https://tedder.me/twilio/hi3.xml', to=k, from_=phone )
After doing that it was easy. I can't say it was done in 15 minutes like John Oliver's tech dude, but I still suspect his wasn't fully working after 15 minutes either.
CommentsComments powered by Disqus