Saturday, May 25, 2013

How to get Sym to send SMS

The first thing that we need is for sym to communicate with us. A simple way is to send an SMS.

Send SMS via Twilio

And twilio.com offers a trial account to programmatically send an SMS.

Below is a python script that interfaces with the twilio api.
Usage:

# twilio_sms.py - a command-line tool to send SMS
# python twilio_sms.py  <recipient> <message>

# Get twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import TwilioRestClient
import sys

def send_sms(number,msg):
# number:str    - Phone number that will receive the SMS
# msg:str        - Message content
    account_sid = "xxxxxxxx"
    auth_token = "yyyyyyyy"
    client = TwilioRestClient(account_sid, auth_token)
    message = client.sms.messages.create(to=number, from_="+1234567890",body=msg)

if __name__ == '__main__':
    [number,msg] = sys.argv[1:3]
    send_sms(number,msg)


Send SMS via Google Calendar

It is also possible to send an SMS using the Google Calendar API. The general idea is as follows:
  1. Create a Google calendar with Notifications enabled to send SMS zero minutes before the appointment
  2. Create a program to add events into that calendar
In effect, everytime an event is added, an SMS will be sent. I'll post the code for that in a later post.

Comparing the two options

All points in favour of Twilio Trial Account SMS:
  1. Twilio Trial SMSes are sent immediately, Google Calendar SMS needs a delay (30s-45s).
  2. Google Calendar SMS requires a one-time manual authentication, Twilio Trial SMS doesn't.
  3. Both options adds text around the actual sms text; but Twilio adds less:
  • Twilio Trial SMS Text: 
    • Sent from your Twilio trial account - <SMS Body>
  • Google Calendar SMS Text: 
    • Reminder: <SMS Body> @ Sat May 25, 2013 08:30 (_)

No comments:

Post a Comment