Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

twilio

Bindings to the Twilio API

  1. Outdated egg!
  2. twilio
    1. Abstract
    2. Documentation
      1. twilio-sid
      2. twilio-auth
      3. twilio-from
      4. twilio-url
      5. twilio-make-call
        1. Examples
      6. twilio-send-sms
        1. Examples
      7. twilio-write
      8. twilio-response
      9. twilio-say
      10. twilio-play
      11. twilio-sms
    3. About this egg
      1. Author
      2. Repository
      3. License
      4. Dependencies
      5. Versions
      6. Colophon

Abstract

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

They are populated initially from the environment variables TWILIO_SID, TWILIO_AUTH, TWILIO_FROM; respectively. It is also possible to set the dynamic parameters twilio-sid, twilio-auth, twilio-from.

Documentation

twilio-sid

[parameter] twilio-sid → (get-environment-variable TWILIO_SID)

The Twilio account SID

(define twilio-sid (make-parameter (get-environment-variable "TWILIO_SID")))

twilio-auth

[parameter] twilio-auth → (get-environment-variable TWILIO_AUTH)

The Twilio auth token

(define twilio-auth (make-parameter (get-environment-variable "TWILIO_AUTH")))

twilio-from

[parameter] twilio-from → (get-environment-variable TWILIO_FROM)

The phone number from which to post

(define twilio-from (make-parameter (get-environment-variable "TWILIO_FROM")))

twilio-url

[parameter] twilio-url → https://~a:~a@api.twilio.com/2010-04-01/Accounts/~a/~a

The Twilio API URL

(define twilio-url
  (make-parameter "https://~a:~a@api.twilio.com/2010-04-01/Accounts/~a/~a"))

twilio-make-call

[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

Make a call using the Twilio API; see http://www.twilio.com/docs/api/rest/making-calls.

to
The phone number to call
url
TwiML URL when the call connects
application-sid
Alternatively, the app containing the URL
method
Method to request url
fallback-url
Second url to try
fallback-method
Method to which to fall back
status-callback
URL to post status to
status-callback-method
Method to use
send-digits
Keys to dial after connecting
if-machine
Determine whether the caller is a machine
timeout
How long to let the phone ring
record
Whether to record the call
(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)))
Examples

Placing a call

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

twilio-send-sms

[procedure] (twilio-send-sms to body #!key status-callback application-sid) → unspecified

Send an SMS using the Twilio API; see http://www.twilio.com/docs/api/rest/sending-sms.

to
The number to send to
body
The SMS to send
status-callback
POST when the message is processed
application-sid
The application's SID
(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)))
Examples

Sending an SMS

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

twilio-write

[procedure] (twilio-write response) → unspecified

Write STwiML as TwiML.

response
The STwiML response
(define twilio-write write-shtml-as-html)

twilio-response

[procedure] (twilio-response . verbs) → STwiML

Wrap verbs in a STwiML response; see http://www.twilio.com/docs/api/twiml.

verbs
The verbs to wrap in a response
(define (twilio-response . verbs) `(Response ,@verbs))

twilio-say

[procedure] (twilio-say text #!key voice loop language) → STwiML

Say something; see http://www.twilio.com/docs/api/twiml/say.

text
The text to say
voice
The voice to say it in
loop
How many times to say it
language
The language to say it in
(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))))

twilio-play

[procedure] (twilio-play url #!key loop) → STwiML

Play something; see http://www.twilio.com/docs/api/twiml/play.

url
The audio file to play
loop
How many times to play it
(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))))

twilio-sms

[procedure] (twilio-sms text #!key to from action method status-callback) → STwiML

Send an SMS; see http://www.twilio.com/docs/api/twiml/sms.

text
The text to send
to
The number to send it to
from
The number to send it from
action
Action URL
method
POST or GET for action
status-callback
Status callback URL
(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))))

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.