2016-07-19 3 views
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('/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

答えて

0

私はtwilioでpythonを使用している場合、これはあなたの電話システムにコールに応答し、発信者を音楽再生中に置き、次にSMSを送信するコードです。発信者を助ける番号。

ここにある:

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 

宣言し、アプリケーション

app = Flask(__name__, static_url_path='/static') 

着信コールを受け入れるために、この番号を設定し、設定します。

@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() 
     response.say("You are number %s in line." % request.form['QueuePosition']) 
     response.play("https://s3-us-west-2.amazonaws.com/" \ 
       "triptorigatwilio/eventpremrigaholdmusic1.mp3") 
     response.redirect('/wait') 

はキューをサポートするために、SMS

client = TwilioRestClient("your account sid...AC...", "your account auth token...xxxx") 
client.sms.messages.create(
to="put number to send sms here", 
from_="put the twilio number to send sms from here", 
body="A caller is in the queue. Call now to help them.", 
) 

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 = True 
    app.run(host='0.0.0.0', port=port) 

twilioでアクティブな番号を設定することを忘れないでください。呼び出し元が呼び出す番号は/ callerを指し、エージェント呼び出しの番号は/ agentを指す必要があります。幸運...

関連する問題