0
import os
from flask import Flask
from flask import request
from flask import url_for
from flask import render_template
from twilio.rest import TwilioRestClient
from twilio import twiml
宣言してSMSを送信し、着信コールを受け入れるためのフリーダイヤルTwilio番号に適用
app = Flask(__name__, static_url_path='/static')
ACCOUNT_SID = "AACxxxxx"
AUTH_TOKEN = "xxxxxx"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
設定にこの番号を設定します。
キュー内の現在位置をユーザに通知し、はTwilioのコーヒーショップコレクションの甘い、なだめるようなサウンドを再生するには待合室 @app.route('/caller', methods=['GET', 'POST'])
def caller():
response = twiml.Response()
response.say("Thank you for calling" \
"Please hold.")
response.enqueue("Queue Demo", waitUrl='/wait')
return str(response)
@app.route('/caller', methods=['GET', 'POST'])
def caller():
response = twiml.Response()
response.say("Thank you for calling" \
"Please hold.")
response.enqueue("Queue Demo", waitUrl='/wait')
return str(response)
設定。
@app.route('/wait', methods=['GET', 'POST'])
def wait():
response = twiml.Response()
twilio_client.sms.messages.create(
to="+44xxxxxxxxxx",
from_="+44xxxxxxxxxx",
body="Hey Jenny! Good luck on the bar exam!",
)
response.say("You are number %s in line." % request.form['QueuePosition'])
response.play("https://s3-us-west-2.amazonaws.com/" \
"twilio/music1.mp3")
response.redirect('/wait')
return str(response)
サポートキューに接続 - エージェントがコールするTwilio番号に割り当てます。
@app.route('/agent', methods=['GET', 'POST'])
def agent():
response = twiml.Response()
with response.dial() as dial:
dial.queue("Queue Demo")
return str(response)
環境によってPORTが指定されていない場合は、開発環境を想定してください。
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
if port == 5000:
app.debug = False
app.run(host='0.0.0.0', port=port)
なぜSMSを送信しないのですか?Pythonはtwilio