Debug custom actions

I am curious to know how to debug custom actions similar to the way I would in normal python development to verify my code before dispatching it.

I have tried adding print statements in my custom actions, but I don’t see them.

Currently, I have an action server that is not dispatching anything and would like to debug that

Thanks in anticipation

1 Like

The prints in your custom actions should appear in the terminal in which you ran rasa run actions.

Thank you. this works correctly. I am trying to use a template to dispatch message. However, in doing so, no message is being dispatched. But when I pass the result of my custom code directly into the dispatcher (without a template), it works correctly.

What do you think could be the cause here?

1 Like

Can you show me your code for that custom action?

class ActionCheckWorldStatistics(Action):
    """Check world covid statistics"""

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

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

        # slots = {"number": None, "total": None}

        try:
            url = "https://disease.sh/v3/covid-19/all"
            print("here")
            res = requests.get(url)
            jsonResult = res.json()
            todayCases = str(jsonResult["todayCases"])
            totalCases = str(jsonResult["cases"])
            
            print(totalCases)

            # slot["number"] = todayCases
            # slot["total"] = totalCases

            responseVars = {
                "number": todayCases,
                "location": "the world",
                "total": totalCases,
            }

            # dispatcher.utter_message(totalCases)
           dispatcher.utter_message(template="utter_statistics", **responseVars)

        except HTTPError as httpError:
            dispatcher.utter_message(f"HTTP error occurred: {httpError}")
        except Exception as err:
            dispatcher.utter_message(f"Other error occurred: {err}")

        return []
1 Like

If you’re using Rasa version 2.4.0, template does not work, only response instead. Both work in 2.4.1 and 2.4.2 though.

template will stop working in Rasa 3.0 anyway, so try using dispatcher.utter_message(response="utter_statistics", **responseVars).

1 Like

Thank you. All good now

1 Like

Happy to help :slight_smile: