在编写欢迎消息以及RASA中的选项时出现问题

在编写欢迎消息以及RASA中的选项时出现问题

本文介绍了在编写欢迎消息以及RASA中的选项时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关如何在RASA中编写欢迎消息的答案,因此,我确实编写了一个自定义操作,但是在会话开始后它不会立即显示该消息,而是在用户发送消息后回复. 以下是我的代码,仅用于打印欢迎消息.我已将其放在"actions.py"文件中.请帮助我解决此问题.

I read this answer on How to code a Welcome Message in RASA, accordingly, I did write a custom action but it is not displaying the message as soon as the session starts, instead, it replies after the user has sent a message. Below is my code for printing just the welcome message. I had put this in my "actions.py" file. Please help me to fix this problem.

下面的图像是我希望我的机器人如何启动的示例,它将以一条常规消息启动,然后提供用户选择的选项.这是我最终要实现的目标.

The image below is an example of How I want my bot to start, It would start up with a general message and then it would give options which the user would be choosing. This is what I am trying to achieve ultimately.

from typing import Text, List, Dict, Any

from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, SessionStarted, ActionExecuted, EventType
from rasa_sdk.executor import CollectingDispatcher


class ActionSessionStart(Action):
    def name(self) -> Text:
        return "action_session_start"

    @staticmethod
    def fetch_slots(dispatcher: CollectingDispatcher, tracker: Tracker) -> List[EventType]:
        """Collect slots that contain the user's name and phone number."""

        slots = []
        return slots


    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[EventType]:

        # the session should begin with a `session_started` event
        dispatcher.utter_message("Hi, I am Aayush Bot !!!")
        events = [SessionStarted()]

        # any slots that should be carried over should come after the
        # `session_started` event
        events.extend(self.fetch_slots(dispatcher, tracker))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events

推荐答案

无论使用什么输入通道,都需要发送/start_session有效负载来触发action_session_start.您可以通过在提示符下键入/start_session来执行此操作.如果要在rasa shell中进行测试,则需要手动发送有效负载.否则,它将在第一个消息(您正在观察的消息)之后开始会话.

Whatever input channel you're using needs to send the /start_session payload to trigger action_session_start. You can do this by just typing /start_session at the prompt. If you're testing this in rasa shell, you need to send the payload manually. Otherwise, it will start the session after the first message (which is what you're observing).

这篇关于在编写欢迎消息以及RASA中的选项时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:19