Skip to content

Instantly share code, notes, and snippets.

@kunal732
Created December 23, 2014 00:10
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 kunal732/1ce19f720a6ff0be2ea8 to your computer and use it in GitHub Desktop.
Save kunal732/1ce19f720a6ff0be2ea8 to your computer and use it in GitHub Desktop.
Mashup of Twilio and SendGrids Parse Webhook
from flask import Flask, request, Response
from twilio.rest import TwilioRestClient
app = Flask(__name__)
sender = 'nobody'
subject = 'nobody'
body = 'nobody'
def voiceaddress(address):
newaddress= address.replace('.',' dot ')
newaddress = newaddress.replace('@',' at ')
newaddress = newaddress.replace('<',',')
newaddress = newaddress.replace('>','')
print newaddress
return newaddress
@app.route ('/dictate/voice.xml', methods =['POST'])
def display():
xml = "<Response><Say voice=\"alice\">You got an email from,, "+sender+". The subject is,, "+subject+". The message is,, "+body+"</Say></Response>"
print xml
return Response(xml, mimetype='text/xml')
@app.route ('/incoming', methods =['POST'])
def nextweb():
global sender
global subject
global body
mailfrom = request.form['from']
sender = voiceaddress(mailfrom)
subject = request.form['subject']
body = request.form['text']
print subject
#Call User and dictate email
# Get these credentials from http://twilio.com/user/account
account_sid = "##########"
auth_token = "##########"
client = TwilioRestClient(account_sid, auth_token)
# Make the call
call = client.calls.create(to="", # Any phone number
from_="", # Must be a valid Twilio number
url="http://yourdomain.com/dictate/voice.xml") #Change domain to where your app lives.
print call.sid
return "OK"
if __name__=='__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment