Skip to content

Instantly share code, notes, and snippets.

@marcesher
Last active February 25, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcesher/403d656ceb0de2d04091d16b4d736f4e to your computer and use it in GitHub Desktop.
Save marcesher/403d656ceb0de2d04091d16b4d736f4e to your computer and use it in GitHub Desktop.
region: us-east-1
function_name: hello_twilio
handler: service.handler
role: lambda_execution_role
description: trying to use lambda to make twilio calls
# if access key and secret are left blank, boto will use the credentials
# defined in the [default] section of ~/.aws/credentials.
aws_access_key_id:
aws_secret_access_key:
# dist_directory: dist
timeout: 15
memory_size: 128
export twilio_sid="your_sid"
export twilio_token="your_token"
export from_number="+your_twilio_number"
export to_number_single_click="+number-to-call-when-single-click" #eg +12135551212
export to_number_double_click="+number-to-call-when-double-click"
export to_number_long_click="+number-to-call-when-long-click"
{
"clickType": "SINGLE"
}
# pip install twilio==6.3.0
from twilio.rest import Client
# you get the sid and token from your Twilio account
client = Client(sid, token)
call = client.api.account.calls \
.create(to=call_to,
from_=call_from,
url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
python-lambda==0.5.0
twilio==6.3.0
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
<Play>http://demo.twilio.com/hellomonkey/monkey.mp3</Play>
</Response>
import os
from twilio.rest import Client
def handler(event, context):
print "Event is "
print event
call_from = os.environ['from_number']
sid = os.environ['twilio_sid']
token = os.environ['twilio_token']
click_type = event.get("clickType")
call_to = os.environ['to_number_single_click']
if click_type == "DOUBLE":
call_to = os.environ['to_number_double_click']
elif click_type == "LONG":
call_to = os.environ['to_number_long_click']
print "Calling %s" % call_to
client = Client(sid, token)
call = client.api.account.calls \
.create(to=call_to,
from_=call_from,
url="http://twimlets.com/message?Message%5B0%5D=Hello%20from%20twilio")
import os
from twilio.rest import Client
def handler(event, context):
call_from = os.environ['from_number']
sid = os.environ['twilio_sid']
token = os.environ['twilio_token']
call_to = os.environ['to_number_single_click']
print "Calling %s" % call_to
client = Client(sid, token)
call = client.api.account.calls \
.create(to=call_to,
from_=call_from,
url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
call = client.api.account.calls\
.create(to="+14085551234", # Any phone number
from_="+12125551234", # Must be a valid Twilio number
url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
call = client.api.account.calls\
.create(to="+14085551234", # Any phone number
from_="+12125551234", # Must be a valid Twilio number
url="http://twimlets.com/message?Message%5B0%5D=Hello%20from%20twilio")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment