Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

206 lines (197 sloc) 8.175 kB

Table of Contents

twilio

Bindings to the Twilio API toc:

= Abstract

Twilio allows one to send SMSes and place calls using their API; and the egg requires at least three pieces of information to do so:

  • The account SID
  • The auth token
  • The from number
They are populated initially from the environment variables , , ; respectively. It is also possible to set the dynamic parameters , , .

= Documentation

<parameter>twilio-sid → (get-environment-variable TWILIO_SID)</parameter> The Twilio account SID <enscript highlight="scheme">(define twilio-sid (make-parameter (get-environment-variable "TWILIO_SID"))) </enscript>

<parameter>twilio-auth → (get-environment-variable TWILIO_AUTH)</parameter> The Twilio auth token <enscript highlight="scheme">(define twilio-auth (make-parameter (get-environment-variable "TWILIO_AUTH"))) </enscript>

<parameter>twilio-from → (get-environment-variable TWILIO_FROM)</parameter> The phone number from which to post <enscript highlight="scheme">(define twilio-from (make-parameter (get-environment-variable "TWILIO_FROM"))) </enscript>

<parameter>twilio-url → https://~a:~a@api.twilio.com/2010-04-01/Accounts/~a/~a</parameter> The Twilio API URL <enscript highlight="scheme">(define twilio-url (make-parameter "https://~a:~a@api.twilio.com/2010-04-01/Accounts/~a/~a")) </enscript>

<procedure>(twilio-make-call to #!key url application-sid method fallback-url fallback-method status-callback status-callback-method send-digits if-machine timeout record) → unspecified</procedure> Make a call using the Twilio API; see http://www.twilio.com/docs/api/rest/making-calls.

: The phone number to call
: TwiML URL when the call connects
: Alternatively, the app containing the URL
: Method to request
: Second to try
: Method to which to fall back
: URL to post status to
: Method to use
: Keys to dial after connecting
: Determine whether the caller is a machine
: How long to let the phone ring
: Whether to record the call
<enscript highlight="scheme">(define (twilio-make-call to #!key url application-sid method fallback-url fallback-method status-callback status-callback-method send-digits if-machine timeout record) (let ((parameters `((from unquote (twilio-from)) (to unquote to) (url unquote url) (application-sid unquote application-sid) (method unquote method) (fallback-url unquote fallback-url) (fallback-method unquote fallback-method) (status-callback unquote status-callback) (status-callback-method unquote status-callback-method) (send-digits unquote send-digits) (if-machine unquote if-machine) (timeout unquote timeout) (record unquote record)))) (with-input-from-request (twilio-url-calls) (upper-camel-filter-parameters parameters) void))) </enscript>

= Examples

Placing a call

 (twilio-make-call "+14158141829" url: "http://example.com/twiml.scm")

<procedure>(twilio-send-sms to body #!key status-callback application-sid) → unspecified</procedure> Send an SMS using the Twilio API; see http://www.twilio.com/docs/api/rest/sending-sms.

: The number to send to
: The SMS to send
: POST when the message is processed
: The application's SID
<enscript highlight="scheme">(define (twilio-send-sms to body #!key status-callback application-sid) (let ((parameters `((from unquote (twilio-from)) (to unquote to) (body unquote body) (status-callback unquote status-callback) (application-sid unquote application-sid)))) (with-input-from-request (twilio-url-sms) (upper-camel-filter-parameters parameters) void))) </enscript>

= Examples

Sending an SMS

 (twilio-send-sms "+14158141829"
                  "If you wish to make an apple pie from scratch, you must first invent the universe.")

<procedure>(twilio-write response) → unspecified</procedure> Write STwiML as TwiML.

: The STwiML response
<enscript highlight="scheme">(define twilio-write write-shtml-as-html) </enscript>

<procedure>(twilio-response . verbs) → STwiML</procedure> Wrap verbs in a STwiML response; see http://www.twilio.com/docs/api/twiml.

: The verbs to wrap in a response
<enscript highlight="scheme">(define (twilio-response . verbs) `(Response ,@verbs)) </enscript>

<procedure>(twilio-say text #!key voice loop language) → STwiML</procedure> Say something; see http://www.twilio.com/docs/api/twiml/say.

: The text to say
: The voice to say it in
: How many times to say it
: The language to say it in
<enscript highlight="scheme">(define (twilio-say text #!key voice loop language) (let ((parameters (lower-camel-filter-parameters `((voice ,voice) (loop ,loop) (language ,language))))) (if (null? parameters) `(Say ,text) `(Say (,(string->symbol "@") ,@(lower-camel-filter-parameters parameters)) ,text)))) </enscript>

<procedure>(twilio-play url #!key loop) → STwiML</procedure> Play something; see http://www.twilio.com/docs/api/twiml/play.

: The audio file to play
: How many times to play it
<enscript highlight="scheme">(define (twilio-play url #!key loop) (let ((parameters (lower-camel-filter-parameters `((loop ,loop))))) (if (null? parameters) `(Play ,url) `(Play (,(string->symbol "@") ,@(lower-camel-filter-parameters parameters)) ,url)))) </enscript>

<procedure>(twilio-sms text #!key to from action method status-callback) → STwiML</procedure> Send an SMS; see http://www.twilio.com/docs/api/twiml/sms.

: The text to send
: The number to send it to
: The number to send it from
: Action URL
: or for
: Status callback URL
<enscript highlight="scheme">(define (twilio-sms text #!key to from action method status-callback) (let* ((parameters (lower-camel-filter-parameters `((to ,to) (from ,from) (action ,action) (method ,method) (status-callback ,status-callback))))) (if (null? parameters) `(Sms ,text) `(Sms (,at ,@(lower-camel-filter-parameters parameters)) ,text)))) </enscript>

= About this egg

Author

Peter Danenberg

Repository

https://github.com/klutometis/twilio

License

BSD

Dependencies

Versions
0.1 : First release: calls and SMS
0.2 : Some Twilio verbs
0.2.1 : Accomodate no parameters.
0.2.2 : Remove the dependency on setup-helper-cock.
0.2.3 : Remove dependency on debug.
0.2.4 : Add cock.
0.2.5 : Use hahn.

Colophon

Documented by hahn.

Jump to Line
Something went wrong with that request. Please try again.