0
背景:我使用Flask和Jinja2模板來創建一個twilio供電的webapp,它將充當基於電話的前端到用戶的webmail。Twilio:如何溝通狀態從客戶端到服務器
的問題:我通過電子郵件列表的神社模板,該模板在迭代循環過的消息,給用戶如何處理每封郵件做一個選擇。 「按1打印,2打回復,3打印。」但是,我不知道如何與服務器通信,在模板正在經歷其循環時應用哪個消息。這裏是我的代碼:
Server代碼:
@app.route('/inbox_action', methods=['GET', 'POST'])
def action():
#1: print
#2: reply
#3: delete
if request.method=='POST' and request.form['Digits']=='1':
#do printing here
render_template('error.html')
elif request.method=='POST' and request.form['Digits']=='2':
#do replying here
pass
elif request.method=='POST' and request.form['Digits']=='3':
#do deleting here
pass
客戶端模板:
<Response>
{% for msg in msgs %}
<Gather numDigits="1" timeout="10" action="/inbox_action">
<Say voice="woman" language="en">To print this message, press 1. To reply to this message, press 2. To delete this message, press 3.</Say>
<Say> {{msg.body}} </Say>
</Gather>
{% endfor %}
</Response>
如何判斷客戶端被打回該消息時,用戶按下了操作的服務器?
我沒有想到將它分成兩個步驟,這是有道理的。如果我使用這種技術,我必須給每個消息一個id,用戶在選擇他們想要處理的消息之前必須選擇一個id。正確? – STN
是的。我會說使用一個唯一的ID是最安全的方法。 –