DEV Community

Discussion on: Announcing the Twilio Hackathon on DEV

 
philnash profile image
Phil Nash

Oh, I see! You're using <Gather input="speech"> to get the text. Sorry, for my misunderstanding.

There's quite a bit going on in that line of your question. event comes from how you would respond to an incoming request to a Twilio Function (which is what the original blog post uses). toLowerCase() in JavaScript is lower() in Python. SpeechResult is a parameter that is sent to your application as part of the webhook request. To deal with those two bits depends on the web app framework you use in Python.

If, for example, you are using Flask. You could do something like this:

from flask import Flask, request
from twilio.twiml.voice_response import VoiceResponse

@app.route("/gather", methods=['GET', 'POST'])
def gather():
    if 'SpeechResult' in request.values:
        speech = request.values['SpeechResult'].lower()
        print("The caller said: ")
        print(speech)

    resp = VoiceResponse()
    return str(resp)

In this example, the direct translation of event.SpeechResult.toLowerCase(); is request.values['SpeechResult'].lower().

Hope that helps!

Thread Thread
 
xmikestax profile image
Michael Oppong

GAANGGGGG, THANK YOU FOR YOUR HELP BRO!
stay blessed!