Вопрос

The context: I'm using Flask with Jinja2 templates to create a twilio-powered webapp which will act as a telephony-based frontend to a user's webmail.

The question: I'm passing a list of email messages to the Jinja template, and the template is iterating in a loop over the messages, giving the user an option of what to do with each message. "Press 1 for print, 2 for reply, 3 for delete." However, I don't know how to communicate to the server which message an action applies to as the template is going through its loop. Here's my code:

Server code:

@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

Client template:

<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>

How do I tell the server which message the client was playing back when the user pressed an action?

Это было полезно?

Решение

Your loop is generating a TwiML response with multiple GATHER verbs, which will not work. Move your loop into the GATHER element so you are generating one GATHER verb but multiple SAY verbs nested within GATHER. I think that will get you up and running.

EDIT: Additionally, you'll have to break this into two steps. 1) Select the message. 2) select print, reply or delete.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top