The Apartment Door Problem


That whole 'Call me and I'll press 9 to buzz you in' thing is the worst.
twilio

Back in my fiscally irresponsible days I kept an apartment in downtown Austin with a roomate. The first thing you find out when you move downtown, is that every single person you know will want to come by and visit, purely to use your guest parking. The problem with this, other than a constant feeling of being used, is that your downtown apartment, will have an annoying buzz-in door.

The Problem

Now, at first sight, the buzz-in door seems pretty simple.

  1. Your friend comes over and parks
  2. Your friend walks over to the door, and dials your apartment number on the callbox
  3. The callbox calls your phone
  4. You answer and dial 9
  5. The callbox hears the dial tone of the 9, and unlocks the door

Very simple… Until you factor in that I had a roomate.

Since our callbox could only store 1 phone number per apartment, and neither one of us wanted to have responsibility for both of our guests and deliveries, we had to use our apartment suggested workaround: A Google Voice number. With that number in the system, the process looked more like this:

  1. Your friend comes over and parks
  2. Your friend walks over to the door, and dials your apartment number on the callbox
  3. The callbox calls our Google Voice number
  4. Google Voice calls both my roomate and I simultaneously
  5. The first one to answer waits until Google Voice connects us to the callbox
  6. You dial 9
  7. You repeat step 6 until…
  8. The callbox hears the dial tone of the 9, and unlocks the door

Needless to say, this got a bit frustrating.

Photo of exterior apartment door with callbox next to it

The door in question

The Solution

This may suprise you, but I did not tell my roomate everytime I ordered pizza, and he did not tell me everytime he had a friend coming by. I would just see Google Voice calling, answer and press 9, even if I wasn’t expecting anyone, because I assumed my roomate was, and I just wanted the ringing to stop, and he would do the same thing.

Essentially, as long as you knew to dial our apartment number, you were getting in. So if it was that simple for a guest, why not make it that simple for us? That’s just what I did… with a Twilio app.

The Twilio API

After a couple of minutes browsing through Twilio’s API docs I found out about TwiML or Twilio Markup Language. The opening sentence of TwiML’s API doc page reads:

TwiML is a set of instructions you can use to tell Twilio what to do when you receive an incoming call or SMS.

which convinced me it was just what I needed for this problem, so I made a Twilio account and got started.

A cursory glance at the TwiML’s API doc page lead me to their “Hello World” program:

<?xml version="1.0" encoding="UTF-8" ?>
<Response>
     <Say>Hello World</Say>
</Response>

Which works great and everything… but it doesn’t press 9, so I kept looking until I found the TwiML Voice Play API page which gives an example of how to wait 1.5 seconds then press 3:

<?xml version="1.0" encoding="UTF-8" ?>
<Response>
    <Play digits="wwww3"></Play>
</Response>

Now we’re talking. Just one last piece. I can’t hear someone knocking on the front door if I’m in my bedroom with the door closed, better have it text me to give me a heads up someone is coming. Good thing Twilio has the TwiML Voice SMS API, which works like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Sms from="+14105551234" to="+14105556789">The king stay the king.</Sms>
</Response>

Time to put it all together.

The Twilio App

In a suprisingly short amount of time, I was able to put this file together which did exactly what I wanted it to do:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
	<Sms to="MY_PHONE_NUMBER" from="MY_TWILIO_NUMBER">Someone is buzzing in.</Sms>
	<Sms to="MY_ROOMMATES_PHONE_NUMBER" from="MY_TWILIO_NUMBER">Someone is buzzing in.</Sms>
	<Say voice="woman">Welcome.</Say>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
	<Pause length="1"/>
	<Play digits="9"/>
</Response>

Some notes:

  1. I had to pay the $1/month for a Twilio phone number, not because the volume was too high for a trial number, but because in order to use the trial number, the caller had to press 9 to run the app, and no one could do that from the box.
  2. The documentation says that putting a ‘w’ in the digits attribute of a Play tag will cause the program to wait .5 seconds, it was not working for me the day I wrote it, so I threw in some pause tags.
  3. The door always opened the first time it heard Twilio play ‘9’, but I had it press ‘9’ 10 times since the workflow for the app was:
    • Call box calls Google Voice
    • Google Voice calls Twilio
    • Twilio answers with app
    • Google Voice connects call box with Twilio
    There was enough of a delay that the call box would never hear the first 1 or 2 ‘9’s
  4. This delay also means that I never heads Twilio say “Welcome.”, but a buddy of mine who I gave this script too skipped the Google Voice step, and has his call box go straight to Twilio, and his guests hear the “Welcome.” everytime.
  5. If you do have the Google Voice step you need to verify the Twilio number with Google Voice. Luckily, Google Voice verifies by calling the number and having the user enter 2 digits when they pick up… and you just wrote a program designed to answer a call and press digits… I’m betting you can figure out how to modify it to verify the number
  6. The Twilio documentation talks a lot about setting up a PHP program to respond to a HTTP request with an XML document, but that’s way too much work. I literally saved the above snippet as an XML file, uploaded it to AWS S3, and set Twilio to do a GET request on it when the number was called and it worked like a champ.
A screenshot showing me receiving 'Someone is buzzing in.' texts

I love it when a plan comes together

comments powered by Disqus