【发布时间】:2019-02-05 18:33:12
【问题描述】:
您好,我正在开发一个 python rasa 聊天机器人项目,该项目使用以下代码教程:https://github.com/RasaHQ/rasa_core/issues/119 允许发布对 rasa 框架的调用。我遇到了一个问题,如果 post 调用以块的形式出现,python 将无法接受这一点。有没有办法通过 Flask 接受分块数据,或者你会推荐不同的 webhook 库吗?提前谢谢!
Python:
class SimpleWebBot(HttpInputComponent):
"""A simple web bot that listens on a url and responds."""
def blueprint(self, on_new_message):
custom_webhook = Blueprint('custom_webhook', __name__)
CORS(custom_webhook)
@custom_webhook.route("/webhook", methods=['POST'])
def receive():
payload = request.json
sender_id = payload.get("sender", None)
text = payload.get("message", None)
out = CollectingOutputChannel()
on_new_message(UserMessage(text, out, sender_id))
responses = [m for _, m in out.messages]
return jsonify(responses)
【问题讨论】:
-
蓝图与卡住的请求没有任何关系,它们是将代码组织成模块的方式。请改写你的问题following this guide advises。