同一父 Response 标签下的多个 Gather 标签
Multiple Gather tags under the same parent Response tag
继续
,我遇到了另一个问题。我花了很多时间尝试各种组合来解决问题,但我想出了 none。
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
<Gather action="/user-A-input" method="POST">
<Say>Please press the input A.</Say>
</Gather>
<Gather action="/user-B-input" method="POST">
<Say>Please press the input B.</Say>
</Gather>
</Response>
但是,当我尝试输入输入A时,它立即挂断,输入B的收集部分没有执行。就我所搜索的而言,没有任何其他人在使用相同逻辑的文档。
这是我的代码 Route.py 中用户 A 输入和用户 B 输入的样子:
@app.route("/user-A-input", methods=['GET', 'POST'])
def UserAInput():
"""Handle key press from a user."""
# Get the digit pressed by the user
#The below logs are not printed, so somehow this method isn't called
logger.debug('before considering user input A')
strA = request.values.get('Digits', None)
logger.debug('In side A| A:' + strA)
resp = VoiceResponse()
return str(resp) #Something feels wrong here
@app.route("/user-B-input", methods=['GET', 'POST'])
def UserBInput():
"""Handle key press from a user."""
# Get the digit pressed by the user
#The below logs are not printed, so somehow this method isn't called
logger.debug('before considering user input B')
strB = request.values.get('Digits', None)
logger.debug('In side B| B:' + strB)
resp = VoiceResponse()
return str(resp) #Something feels wrong here
如果有人能帮助我理解我到底搞砸了什么,我将不胜感激。可能与 return 有关,但我不确定。或者可能是解决问题的方法。我计划使用输入 A 和 B 并进行 API 调用以获取数据并将其返回给用户。
这里是 Twilio 开发人员布道者。
您不能在同一个回复中使用两个 <Gather>
标签。但是,您可以通过一些更改来获得所需的结果。
让我先解释一下发生了什么。当 Twilio 在某些 TwiML 中达到 <Gather>
时,它会等待收集用户的响应,然后将响应提交给 action
URL 并将调用也定向到 URL .在一个动作中 <Gather>
之后什么都看不到。
要做的是 return 你的 /user-A-input
第二个 <Gather>
。
像这样:
第一个 TwiML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
<Gather action="/user-A-input" method="POST">
<Say>Please press the input A.</Say>
</Gather>
</Response>
用户A输入
@app.route("/user-A-input", methods=['GET', 'POST'])
def UserAInput():
"""Handle key press from a user."""
logger.debug('before considering user input A')
strA = request.values.get('Digits', None)
logger.debug('In side A| A:' + strA)
resp = VoiceResponse()
gather = Gather(action='/user-B-input')
gather.say('Please press the input B.')
resp.append(gather)
return str(resp)
那么用户 B 输入应该可以正常工作。
最后一点,您目前依赖 <Gather>
的默认超时,这意味着 Digits
将在用户停止输入 5 秒后或如果他们按下 [=] 20=] 键。如果您期望一定数量的输入,您可以使用 numDigits
attribute of <Gather>
. You can also set other finishing keys with the finishOnKey
attribute.
如果有帮助请告诉我。
虽然我想不出一个合乎道德和正确的解决方案,但我还是想出了一个方法来解决这个问题,将用户 A 输入、用户 B 输入和 API 在 user-A-input 方法中调用请求(我需要输入 A 和 B 的请求)。在接收输入 A 的最后,我将调用重定向到主要方法(“/”),该方法又再次调用 user-A-input,但有一些标志帮助我跳过输入 A 部分并直接进入输入 B 部分,我确保将其记录在正确的变量中,然后将输入 A 和 B 传递给另一个 API 以获得响应。这听起来可能有点模糊和复杂,但如果您检查my git repo,您一定会明白。我希望是否有更好的解决方案。
继续
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
<Gather action="/user-A-input" method="POST">
<Say>Please press the input A.</Say>
</Gather>
<Gather action="/user-B-input" method="POST">
<Say>Please press the input B.</Say>
</Gather>
</Response>
但是,当我尝试输入输入A时,它立即挂断,输入B的收集部分没有执行。就我所搜索的而言,没有任何其他人在使用相同逻辑的文档。
这是我的代码 Route.py 中用户 A 输入和用户 B 输入的样子:
@app.route("/user-A-input", methods=['GET', 'POST'])
def UserAInput():
"""Handle key press from a user."""
# Get the digit pressed by the user
#The below logs are not printed, so somehow this method isn't called
logger.debug('before considering user input A')
strA = request.values.get('Digits', None)
logger.debug('In side A| A:' + strA)
resp = VoiceResponse()
return str(resp) #Something feels wrong here
@app.route("/user-B-input", methods=['GET', 'POST'])
def UserBInput():
"""Handle key press from a user."""
# Get the digit pressed by the user
#The below logs are not printed, so somehow this method isn't called
logger.debug('before considering user input B')
strB = request.values.get('Digits', None)
logger.debug('In side B| B:' + strB)
resp = VoiceResponse()
return str(resp) #Something feels wrong here
如果有人能帮助我理解我到底搞砸了什么,我将不胜感激。可能与 return 有关,但我不确定。或者可能是解决问题的方法。我计划使用输入 A 和 B 并进行 API 调用以获取数据并将其返回给用户。
这里是 Twilio 开发人员布道者。
您不能在同一个回复中使用两个 <Gather>
标签。但是,您可以通过一些更改来获得所需的结果。
让我先解释一下发生了什么。当 Twilio 在某些 TwiML 中达到 <Gather>
时,它会等待收集用户的响应,然后将响应提交给 action
URL 并将调用也定向到 URL .在一个动作中 <Gather>
之后什么都看不到。
要做的是 return 你的 /user-A-input
第二个 <Gather>
。
像这样:
第一个 TwiML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
<Gather action="/user-A-input" method="POST">
<Say>Please press the input A.</Say>
</Gather>
</Response>
用户A输入
@app.route("/user-A-input", methods=['GET', 'POST'])
def UserAInput():
"""Handle key press from a user."""
logger.debug('before considering user input A')
strA = request.values.get('Digits', None)
logger.debug('In side A| A:' + strA)
resp = VoiceResponse()
gather = Gather(action='/user-B-input')
gather.say('Please press the input B.')
resp.append(gather)
return str(resp)
那么用户 B 输入应该可以正常工作。
最后一点,您目前依赖 <Gather>
的默认超时,这意味着 Digits
将在用户停止输入 5 秒后或如果他们按下 [=] 20=] 键。如果您期望一定数量的输入,您可以使用 numDigits
attribute of <Gather>
. You can also set other finishing keys with the finishOnKey
attribute.
如果有帮助请告诉我。
虽然我想不出一个合乎道德和正确的解决方案,但我还是想出了一个方法来解决这个问题,将用户 A 输入、用户 B 输入和 API 在 user-A-input 方法中调用请求(我需要输入 A 和 B 的请求)。在接收输入 A 的最后,我将调用重定向到主要方法(“/”),该方法又再次调用 user-A-input,但有一些标志帮助我跳过输入 A 部分并直接进入输入 B 部分,我确保将其记录在正确的变量中,然后将输入 A 和 B 传递给另一个 API 以获得响应。这听起来可能有点模糊和复杂,但如果您检查my git repo,您一定会明白。我希望是否有更好的解决方案。