Muhamad Asyraf Othman
Muhamad Asyraf Othman

Reputation: 33

Setting the action on rasa restart

Hi I'm trying to set some message to be uttered when the user restart the conversation. I have asked in Rasa Forum and tried to change the code. But it returned this error

AttributeError: ‘Tracker’ object has no attribute ‘utter_message’

This is the code that I wrote:

class ActionRestarted(Action):
""" This is for restarting the chat"""

def name(self) -> Text:
    return "action_restart"

async def run(
        self,
        tracker: Tracker,
        dispatcher: CollectingDispatcher,
        domain: Dict[Text, Any],) -> List[Event]:
    from rasa.core.events import Restarted

    # only utter the template if it is available
    evts = await super().run(tracker, domain, dispatcher.utter_message("Restarted"))
    return evts + [Restarted()]

Feel free to point out my mistake and correct them thank you

Upvotes: 0

Views: 858

Answers (1)

Visvamba Nathan
Visvamba Nathan

Reputation: 135

You are trying to pass the return value of utter_message as the dispatcher parameter of super.run(), where it expects a CollectingDispatcher object.

You can just call utter_message from your run method.

async def run(
        self,
        tracker: Tracker,
        dispatcher: CollectingDispatcher,
        domain: Dict[Text, Any],) -> List[Event]:
    from rasa.core.events import Restarted

    dispatcher.utter_message("Restarted")
    return [Restarted()]

Upvotes: 1

Related Questions