- Published on
So how did you do that text stuff?
- Authors
- Name
- Christopher Wormwood
I did cool sms stuff for Beasts of the Field directed by my lovely sibling niky and starring gannon and dylan, but how, how did I do it? Why is theater so gatekept? If only you were also a techbro and could make cool shit! SHUT UP
Step One
Go to twilio and sign up
Step Two
assuming you want a normal looking phone number, exit the free trial and buy a 10DLC number in the area code you want. Release the toll free one they give you for the trial. This is a couple bucks as of 2023.
Step Hell: Register Your a2p Campaign.
Just keep clicking the most reasonable thing you see in the various menus here. (Sole proprietor? Sure. What category is this in? Uhhh information? Whatever.)
Verbal consent is a thing here, don't worry you aren't going to have to ruin your play with REPLY YES TO RECEIVE THEATER (I was worried) but you do have to explain how your campaign gets that consent. For instance, even after putting something that I felt was fairly reasonable like:
Users are told about the text interation before the play and initiate the interaction by seeing the number projected and choosing to text it, after which they are automatically opted out
My campain was still rejected.
And it took something like three days to get rejected too.
I was at that point extremely annoyed that I couldn't just set up my dinky little theater trick that was pretty obviously not going to spam anyone so I submitted this:
expecting to be rejected by how obviously a lie it was.
(cell phone carriers if ur reading this actually it wasn't a lie; actually right now I'm lying to my cool theater friends to make them think I didn't do this kind of lame thing but in reality every performance began with exactly that process and everyone knew exactly what they were getting into when texting the mysterious number on screen. all further communication will be through my lawyers)Came back a few days later ready to be punished for my snark and—oh shit they accepted it.
Well great.
Step Four: Code Some Shit
This step might sound intimidating but it's not at all that bad, chatgpt can and did write everything for me. I can't actually remember what I asked it something like:
I need a node app that uses the twilio api to respond to incoming messages.
If this is your first time ever working with code you should google a basic intro to nodejs for how to install node and understand how to type arcane looking things into your console and press enter.
Things like npm install
to install the depedencies at the top of the file and how to run your program (node whateverTheNameIs.js
) but that's basically it. Here's what I ended up using:
const express = require('express')
const bodyParser = require('body-parser')
const MessagingResponse = require('twilio').twiml.MessagingResponse
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
const imageUrls = [
// urls for all the images I send out in a big list, I used imgur to host
// these. twilio wants a url to an image they can send to the user, they
// don't support you responding with the image itself
"http://www.imgur.com/someImage.jpg",
"http://www.imgur.com/anotherImage.jpg "
]
const isFirstTextHashMap = {}
app.post('/sms', (req, res) => {
const twiml = new MessagingResponse()
const sender = req.body.From
// only reply if we've never texted this number before
// (you don't need this, I just didn't want to reply with another beast every
// time someone texted the number)
if (!isFirstTextHashMap[sender]) {
isFirstTextHashMap[sender] = true
// randomly choose an image to send
const randomIndex = Math.floor(Math.random() * imageUrls.length)
twiml.message({ to: sender }).media(imageUrls[randomIndex])
twiml.message(`Thank You For Being An Angel And Maybe Saving This Beast`)
}
res.writeHead(200, { 'Content-Type': 'text/xml' })
res.end(twiml.toString())
})
app.listen(3000, () => {
console.log('Server is running on port 3000')
})
Step Five: ngrok
Twilio themselves recommend using ngrok and it's very convenient as a way to open up a project to the larger internet. So if you've built off my example above you'll want to download ngrok, sign up on their site and follow the steps to configure your auth key.
After all that you can start letting in requests to your lil node server by running ngrok http 3000
Step Six: configure twilio
Now the only step remaining is to go over to twilio where you hopefully have an approved a2p campaign and click on the 10DLC number you bought. Scroll all the way down that page until you see messaging configuration and paste in your ngrok url followed by the path of your specific endpoint (I called mine /sms so I added that to the end of the url like so):
After that you should be good to go, give it a test. Make weird theater stuff.
Also remember that this is RUNNING ON YOUR COMPUTER SO DON'T CLOSE IT OR LET IT DIE DURING THE SHOW OH SHIT
Also if you disconnect and reconnect to ngrok you're going to get a different url so you'll have to go back yet again to twilio and update it with your new url but that's the price we pay for using shit that's free.
Altogether the setup and registration probably ended up costing me $20 or so in twilio costs buying the number and getting the a2p campaign. Once that's set up sending out individual texts only costs you cents. Remember to release your phone number after your done using it because that costs like 2 bucks a month as well.
And that's all folks. Thanks for coming out to see Beasts of the Field and the other milking the beast plays or if you just found this post in some other way then thanks for being your very special you.