Twilio phone calls by Dropbox phone book

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

This simple Twilio example works with HTTPS based Twilio API from mbed, makes phone calls and talks text speech message by referring phone book file in Dropbox.

For using this example:

- Prepare mbed with Ethernet connection.

- Go to http://twilio.com, and sign up.

- Copy Twilio Sid, Token, phone number and TwiML URL in twilio.cpp.

static char twilio_AccountSid[] = "TWILIO_ACCOUNT_SID" ;
static char twilio_AuthToken[]  = "AUTH_TOKEN" ;
static const char twilio_From[] = "PHONE_NUMBER_FROM" ;
static const char twilio_Url[]  = "http://twimlbin.com/TWIML_PATH" ;

- Copy Dropbox file link URL to dropbox.cpp.

static char Dropbox_URL[] = "https://www.dropbox.com/PHONE_LIST_FILE" ;

- The demo makes a call from Twilio to the phone numbers listed on the Dropbox phone book. Phone book is list of the number CSV file.

- Set up a TwiML web page defining Twilio action, set the url to twilio_Url.

TwiML first step example:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
	<Say language="ja-JP">もしもし。聞こえますか?こちらツイリオです</Say>
</Response>

- Build, download it to mbed, and you will get a call on your phone.

Have fun!

For FRDM-k64f: http://mbed.org/users/wolfSSL/code/CyaSSL-Twilio-Dropbox-FRDM/

日本語:http://mbed.org/users/wolfSSL/code/CyaSSL-Twilio/wiki/CyaSSL-Twilio-Dropbox-jp

Committer:
wolfSSL
Date:
Mon Jul 21 11:29:59 2014 +0000
Revision:
0:ca5715c208bf
Twilio phone calls with Dropbox phone book;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:ca5715c208bf 1 /* twilio.cpp */
wolfSSL 0:ca5715c208bf 2 /* Copyright (C) 2014 wolfSSL, MIT License
wolfSSL 0:ca5715c208bf 3 *
wolfSSL 0:ca5715c208bf 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
wolfSSL 0:ca5715c208bf 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
wolfSSL 0:ca5715c208bf 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
wolfSSL 0:ca5715c208bf 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
wolfSSL 0:ca5715c208bf 8 * furnished to do so, subject to the following conditions:
wolfSSL 0:ca5715c208bf 9 *
wolfSSL 0:ca5715c208bf 10 * The above copyright notice and this permission notice shall be included in all copies or
wolfSSL 0:ca5715c208bf 11 * substantial portions of the Software.
wolfSSL 0:ca5715c208bf 12 *
wolfSSL 0:ca5715c208bf 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
wolfSSL 0:ca5715c208bf 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
wolfSSL 0:ca5715c208bf 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
wolfSSL 0:ca5715c208bf 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wolfSSL 0:ca5715c208bf 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
wolfSSL 0:ca5715c208bf 18 */
wolfSSL 0:ca5715c208bf 19 #include "mbed.h"
wolfSSL 0:ca5715c208bf 20 #include "HTTPClient.h"
wolfSSL 0:ca5715c208bf 21
wolfSSL 0:ca5715c208bf 22 extern HTTPClient http;
wolfSSL 0:ca5715c208bf 23
wolfSSL 0:ca5715c208bf 24 static char str[1500] ;
wolfSSL 0:ca5715c208bf 25
wolfSSL 0:ca5715c208bf 26 void twilio_main(const char *phone)
wolfSSL 0:ca5715c208bf 27 {
wolfSSL 0:ca5715c208bf 28 int ret ;
wolfSSL 0:ca5715c208bf 29
wolfSSL 0:ca5715c208bf 30 #define ALLOWANCE 100
wolfSSL 0:ca5715c208bf 31 #define SAFIX 10
wolfSSL 0:ca5715c208bf 32
wolfSSL 0:ca5715c208bf 33 static char twilio_AccountSid[] = "TWILIO_ACCOUNT_SID" ;
wolfSSL 0:ca5715c208bf 34 static char twilio_AuthToken[] = "AUTH_TOKEN" ;
wolfSSL 0:ca5715c208bf 35 static const char twilio_From[] = "PHONE_NUMBER_FROM" ;
wolfSSL 0:ca5715c208bf 36 static const char twilio_Url[] = "http://twimlbin.com/TWIML_PATH" ;
wolfSSL 0:ca5715c208bf 37
wolfSSL 0:ca5715c208bf 38 static const char *twilio_To = phone ;
wolfSSL 0:ca5715c208bf 39 static const char twilio_api[] = "https://api.twilio.com/2010-04-01/Accounts/%s/%s.%s" ;
wolfSSL 0:ca5715c208bf 40 static const char twilio_Method[] = "GET" ;
wolfSSL 0:ca5715c208bf 41 static const char twilio_FBMethod[] = "GET" ;
wolfSSL 0:ca5715c208bf 42 static const char twilio_StatusCBM[]= "GET" ;
wolfSSL 0:ca5715c208bf 43 static const char twilio_Record[] = "false" ;
wolfSSL 0:ca5715c208bf 44
wolfSSL 0:ca5715c208bf 45 static char twilio_request[] = "Calls" ;
wolfSSL 0:ca5715c208bf 46 static char twilio_twiML[] = "xml" ;
wolfSSL 0:ca5715c208bf 47
wolfSSL 0:ca5715c208bf 48 static char uri[
wolfSSL 0:ca5715c208bf 49 sizeof(twilio_AccountSid)
wolfSSL 0:ca5715c208bf 50 +sizeof(twilio_AuthToken)
wolfSSL 0:ca5715c208bf 51 +sizeof(twilio_api)
wolfSSL 0:ca5715c208bf 52 +SAFIX+ALLOWANCE] ;
wolfSSL 0:ca5715c208bf 53 static char HeaderLines[] =
wolfSSL 0:ca5715c208bf 54 "User-Agent: CyaSSL-Twilio,1.0\n"
wolfSSL 0:ca5715c208bf 55 "Host: api.twilio.com\n"
wolfSSL 0:ca5715c208bf 56 "Accept: */*\n" ;
wolfSSL 0:ca5715c208bf 57
wolfSSL 0:ca5715c208bf 58 //POST data
wolfSSL 0:ca5715c208bf 59 HTTPMap params;
wolfSSL 0:ca5715c208bf 60 HTTPText inText(str, 1500);
wolfSSL 0:ca5715c208bf 61
wolfSSL 0:ca5715c208bf 62 params.put("From", twilio_From);
wolfSSL 0:ca5715c208bf 63 params.put("To", twilio_To);
wolfSSL 0:ca5715c208bf 64 params.put("Url", twilio_Url);
wolfSSL 0:ca5715c208bf 65 params.put("Method", twilio_Method);
wolfSSL 0:ca5715c208bf 66 params.put("FaulbackMethod", twilio_FBMethod);
wolfSSL 0:ca5715c208bf 67 params.put("StatusCallbackMethod", twilio_StatusCBM);
wolfSSL 0:ca5715c208bf 68 params.put("Record", twilio_Record);
wolfSSL 0:ca5715c208bf 69
wolfSSL 0:ca5715c208bf 70 printf("\nCalling %s\n", twilio_To);
wolfSSL 0:ca5715c208bf 71 sprintf(uri, twilio_api, twilio_AccountSid, twilio_request, twilio_twiML) ;
wolfSSL 0:ca5715c208bf 72
wolfSSL 0:ca5715c208bf 73 http.basicAuth(twilio_AccountSid, twilio_AuthToken);
wolfSSL 0:ca5715c208bf 74 http.setHeader(HeaderLines) ;
wolfSSL 0:ca5715c208bf 75 http.setSSLversion(1) ; /* TLSv1.0 */
wolfSSL 0:ca5715c208bf 76
wolfSSL 0:ca5715c208bf 77 ret = http.post(uri, params, &inText);
wolfSSL 0:ca5715c208bf 78 if (ret == HTTP_OK) {
wolfSSL 0:ca5715c208bf 79 printf("Executed POST successfully - read %d characters\n", strlen(str));
wolfSSL 0:ca5715c208bf 80 printf("Result: %s\n", str);
wolfSSL 0:ca5715c208bf 81 } else {
wolfSSL 0:ca5715c208bf 82 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
wolfSSL 0:ca5715c208bf 83 }
wolfSSL 0:ca5715c208bf 84 }