lappis-unb/rasa-ptbr-boilerplate

View on GitHub
bot/actions/custom_action_example.py

Summary

Maintainability
A
0 mins
Test Coverage
from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import UserUtteranceReverted


class ActionExemplo(Action):
    def name(self) -> Text:
        return "action_exemplo"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        dispatcher.utter_message(text="Esta mensagem esta sendo enviada do RASA SDK!!!")
        return []


class ActionDefaultFallback(Action):
    """Executes the fallback action and goes back to the previous state
    of the dialogue"""

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

    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        dispatcher.utter_message(template="utter_core_fallback")

        # Revert user message which led to fallback.
        return [UserUtteranceReverted()]