[英]How to get latest bot response in rasa Chatbot?
How to get latest bot response with Rasa Chatbot?如何使用 Rasa Chatbot 获得最新的机器人响应?
For getting user input we use : tracker.latest_message['text']为了获取用户输入,我们使用: tracker.latest_message['text']
So, what is syntax for getting latest bot response ?那么,获取最新机器人响应的语法是什么?
Thanks谢谢
You can use the tracker.events
list to fetch the latest bot event.您可以使用
tracker.events
列表来获取最新的机器人事件。
bot_event = next(e for e in reversed(tracker.events) if e["event"] == "bot")
This will go through the reversed list of events (making it from latest to oldest) and pick the first bot event using the next()
function.这将遍历事件的反向列表(从最新到最旧),并使用
next()
函数选择第一个机器人事件。
The event will be have the following format:活动将采用以下形式:
{'event': 'bot', 'timestamp': 1601789469.174273, 'text': 'Hey! How are you?', 'data': {'elements': None, 'quick_replies': None, 'buttons': None, 'attachment': None, 'image': None, 'custom': None}, 'metadata': {}}
There you can simply take the 'text'
param if you are only interested in the message.如果您只对消息感兴趣,您可以在那里简单地采用
'text'
参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.