I built a thing: text your US postal address to (520) 200-2223 and get a text back with your state & federal legislative rep phone numbers.— John Emerson (@backspace) November 20, 2016
I built an SMS bot! Here’s the story: I’ve been looking at bots for advocacy and have been keeping a short list of inspiring SMS projects including TXTMob, Crises Text Line, mRelief, Planned Parenthood’s Teen Q&A line, and others. I’ve poked around the Twilio API. And then came this message on the Progressive Exchange email list:
Subject: ISO "find your elected officials" by text
I have to think this exists -- is there a simple "text KEYWORD to THIS NUMBER" that will return the names and phone numbers of your elected officials? Congress and state?
Turns out it does not exist — so I wired it up and announced it on the list. The response has been super positive.
In the last few weeks, around 3,000 people have texted the bot and folks have been sharing screenshots of their results on Twitter and Facebook.
Here’s how it works: Plivo receives a text message at a phone number and sends a POST to a Node.js script I’m running on a server. My script geolocates the postal address using the Google Maps API and then send the resulting latitude and longitude to the Google Civic API for the names and numbers of representatives. The script then formats the resulting data and then sends back out a text message through Plivo.
There are a few fail-safes: when Google Maps can’t geolocate an address I fall back to the MapQuest API, and when Google Civic does not return state legislators I fall back to the Sunlight Foundation’s OpenStates API.
The vast majority of users are sending ZIP codes instead of postal addresses, which makes finding reps a little complicated. ZIP code boundaries do not always align with electoral district boundaries, and more than one district may overlap a given ZIP. Google Civic seems pretty strict and does not return potentially incorrect information, so if you just send it a ZIP code it may not return state-level reps at all. OpenStates is more forgiving, though may not be as up-to-date. When I geolocate a ZIP code, I get it’s center point and see what district that point is in.
Some folks have been cautious about sharing their personal info. I keep the data for 24 hours for debugging and Plivo logs the numbers to bill me for usage. I absolutely will not share or sell people’s personal information.
It was a strange, disembodied experience building an “app” with no graphical front-end and no content management system on the backend. The design here is all in the tone and formatting of the text.
Here are a few things I learned:
In any case, the source code of my bot on GitHub if you’re inclined, though it’s ugly and there’s some nested callback hell that could use some serious refactoring. But it works and is running now and is bringing people delight and power. Which is pretty satisfying.