Skip to content

Instantly share code, notes, and snippets.

@shivkanthb
Created April 3, 2023 22:05
Show Gist options
  • Save shivkanthb/bc34578e4d7a50103634026e714318b6 to your computer and use it in GitHub Desktop.
Save shivkanthb/bc34578e4d7a50103634026e714318b6 to your computer and use it in GitHub Desktop.
callboxbot
from flask import Flask, request, Response
from twilio.twiml.voice_response import VoiceResponse, Gather
from twilio.rest import Client
import os
app = Flask(__name__)
account_sid = os.environ['ACCOUNT_SID']
auth_token = os.environ['AUTH_TOKEN']
twilio_phone_number = os.environ['PHONE_NUMBER']
client = Client(account_sid, auth_token)
@app.route('/incoming_call', methods=['POST'])
def incoming_call():
response = VoiceResponse()
response.say(
"Hey there! How can I help you? Please enter the access code followed by the pound sign."
)
gather = Gather(action='/process_gather', method='POST', finish_on_key='#')
response.append(gather)
response.redirect('/incoming_call')
return Response(str(response), 200, mimetype='text/xml')
@app.route('/process_gather', methods=['POST'])
def process_gather():
entered_digits = request.form.get('Digits', '')
print(f"Entered digits: {entered_digits}")
response = VoiceResponse()
if entered_digits == '420':
response.say("Alright! letting you in now ")
response.play(digits='9')
response.play(digits='9')
response.play(digits='9')
else:
response.say(f"You entered {entered_digits} bruh you cant come in")
response.hangup()
return Response(str(response), 200, mimetype='text/xml')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment