Skip to content

Instantly share code, notes, and snippets.

@meganspeir
Last active February 11, 2016 23:50
Show Gist options
  • Save meganspeir/33954896b4f6d6d7f6b4 to your computer and use it in GitHub Desktop.
Save meganspeir/33954896b4f6d6d7f6b4 to your computer and use it in GitHub Desktop.
Human Detection with <Gather>
'''
README:
1. Create a free Twilio account and snag a phone number: https://www.twilio.com/try-twilio
2. Create a webhook to configure Twilio voice URL: https://www.twilio.com/blog/2015/09/6-awesome-reasons-to-use-ngrok-when-testing-webhooks.html
3. Install Flask: http://flask.pocoo.org/docs/0.10/installation/
4. Install Twilio-Python helper library: https://www.twilio.com/docs/python/install
5. Copy & paste this gist. Be sure to edit YOUR information. Have fun!
'''
from flask import Flask
from twilio import twiml
from twilio.rest import TwilioRestClient
# Grab your Account Sid and Auth Token from twilio.com/user/account
account_sid = "YOUR_ACCOUNT_SID"
auth_token = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(account_sid, auth_token)
app = Flask(__name__)
@app.route('/voice', methods=['POST'])
def detect_humans():
r = twiml.Response()
r.say("Machines don't press keys, but humans do. Press a key now.")
r.gather(timeout="10", action="http://twimlbin.com/external/0d2c3c0909a0e23e")
r.say("Too bad, you did not press a key.")
return str(r)
call = client.calls.create(to="YOUR_NUMBER", from_="YOUR_TWILIO_NUMBER", url='YOUR_VOICE_URL')
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment