在使用ngrok测试我的应用程序时,我的两个用户同时发了Twilio号码,他们在同一个会话中登陆,因此我使用的任何计数器都会因各自的用户体验而出错。我如何才能确保每个用户短信号码使用该应用程序将有自己的独立体验?在Flask会话中创建动态密钥的诀窍是什么?你知道吗
下面是一些代码
from flask import Flask, request, session
from twilio.twiml.messaging_response import MessagingResponse
SECRET_KEY = 'a secret key'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route("/sms", methods=['GET','POST'])
def sms_logic():
try:
# Increment the counter
counter = session.get('counter',0)
# Initiate conversation + Save the new counter value in the session
body = request.values.get('Body', None)
counter += 1
session['counter'] = counter
# start our TwiML response
resp = MessagingResponse()
if counter == 1 and body.lower() == 'target_string':
resp.message('response 1')
elif counter == 1 and body.lower() != 'target_string':
resp.message('Unknown entry. Please try again.')
session.clear()
else:
resp.message('response 2 ')
session.clear()
#print(counter)
return(str(resp))
except Exception as e:
pass
if __name__ == "__main__":
app.run(debug=True)
我正在清除会话以重置计数器,而不是等待4小时等待会话过期,特别是如果用户希望再次通过应用程序进行另一项输入。你知道吗
提前谢谢!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐