Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask import jsonify
- #from flask import render_template
- #from flask import request
- from flask import url_for
- from twilio.twiml.voice_response import VoiceResponse
- from twilio.rest import Client
- app = Flask(__name__)
- # Voice Request URL
- @app.route('/call')
- def call():
- # Get phone number we need to call
- phone_number = request.form.get('phoneNumber', None)
- try:
- twilio_client = Client(app.config['TWILIO_ACCOUNT_SID'],
- app.config['TWILIO_AUTH_TOKEN'])
- except Exception as e:
- msg = 'Missing configuration variable: {0}'.format(e)
- return jsonify({'error': msg})
- try:
- twilio_client.calls.create(from_=app.config['TWILIO_CALLER_ID'],
- to=phone_number,
- url=url_for('.outbound',
- _external=True))
- except Exception as e:
- app.logger.error(e)
- return jsonify({'error': str(e)})
- return jsonify({'message': 'Call incoming!'})
- @app.route('/outbound', methods=['POST'])
- def outbound():
- response = VoiceResponse()
- response.say("Thank you for contacting our sales department. If this "
- "click to call application was in production, we would "
- "dial out to your sales team with the Dial verb.",
- voice='alice')
- response.number("+16518675309")
- return str(response)
- if __name__ == '__main__':
- app.run()
Add Comment
Please, Sign In to add comment