Rasa External Events - Action not sending message

Hi everyone,

I’m trying to follow this example https://rasa.com/docs/rasa/reaching-out-to-user#external-events I was able to send a POST request to trigger an intent and therefore an action but I’m not receiving the message from the action server.

https://github.com/joaomsimoes/rasa_hl the github repo.

The POST request.

curl -H "Content-Type: application/json" -X POST \
  -d '{"name": "EXTERNAL_notification"}' \
  "http://localhost:5005/conversations/2079662765/trigger_intent"

The bot received the POST request and triggered the right intent and action, but the action server is not sending the message back to the bot. On the NotificationToUser class, I did write a print() message to debug and every time I send the post request I can see the printed message in the console. Meaning that everything is working until this point (?). But I don’t receive the message in Telegram. I also created two other actions that are actually working with no problems.

The logs from the POST request

{
    "tracker": {
        "sender_id": "2079662765",
        "slots": {
            "session_started_metadata": null
        },
        "latest_message": {
            "intent": {
                "name": "EXTERNAL_notification"
            },
            "entities": [],
            "text": "EXTERNAL: EXTERNAL_notification",
            "message_id": null,
            "metadata": {
                "is_external": true
            }
        },
        "latest_event_time": 1671602339.587904,
        "followup_action": null,
        "paused": false,
        "events": [
            {
                "event": "action",
                "timestamp": 1671602322.3021328,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_session_start",
                "policy": null,
                "confidence": 1.0,
                "action_text": null,
                "hide_rule_turn": false
            },
            {
                "event": "session_started",
                "timestamp": 1671602322.3021328,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                }
            },
            {
                "event": "action",
                "timestamp": 1671602322.3021328,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_listen",
                "policy": null,
                "confidence": null,
                "action_text": null,
                "hide_rule_turn": false
            },
            {
                "event": "user",
                "timestamp": 1671602322.3173356,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "text": "id",
                "parse_data": {
                    "intent": {
                        "name": "get_id",
                        "confidence": 0.8244315981864929
                    },
                    "entities": [],
                    "text": "id",
                    "message_id": "22960d09556d4e25bc7d0b38b1b98e63",
                    "metadata": {},
                    "text_tokens": [
                        [
                            0,
                            2
                        ]
                    ],
                    "intent_ranking": [
                        {
                            "name": "get_id",
                            "confidence": 0.8244315981864929
                        },
                        {
                            "name": "affirm",
                            "confidence": 0.149237722158432
                        },
                        {
                            "name": "goodbye",
                            "confidence": 0.025942504405975342
                        },
                        {
                            "name": "deny",
                            "confidence": 0.0003484852204564959
                        },
                        {
                            "name": "knowledge_question",
                            "confidence": 3.974913852289319e-5
                        }
                    ],
                    "response_selector": {
                        "all_retrieval_intents": [],
                        "default": {
                            "response": {
                                "responses": null,
                                "confidence": 0.0,
                                "intent_response_key": null,
                                "utter_action": "utter_None"
                            },
                            "ranking": []
                        }
                    }
                },
                "input_channel": "telegram",
                "message_id": "22960d09556d4e25bc7d0b38b1b98e63"
            },
            {
                "event": "user_featurization",
                "timestamp": 1671602324.4174042,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "use_text_for_featurization": false
            },
            {
                "event": "action",
                "timestamp": 1671602324.4174042,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_get_id",
                "policy": "RulePolicy",
                "confidence": 1.0,
                "action_text": null,
                "hide_rule_turn": true
            },
            {
                "event": "bot",
                "timestamp": 1671602324.4174042,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "text": "The ID of this conversation is '2079662765'.",
                "data": {
                    "elements": null,
                    "quick_replies": null,
                    "buttons": null,
                    "attachment": null,
                    "image": null,
                    "custom": null
                }
            },
            {
                "event": "action",
                "timestamp": 1671602324.5494268,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_listen",
                "policy": "RulePolicy",
                "confidence": 1.0,
                "action_text": null,
                "hide_rule_turn": true
            },
            {
                "event": "user",
                "timestamp": 1671602337.4851956,
                "metadata": {
                    "is_external": true,
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "text": "EXTERNAL: EXTERNAL_notification",
                "parse_data": {
                    "intent": {
                        "name": "EXTERNAL_notification"
                    },
                    "entities": [],
                    "text": "EXTERNAL: EXTERNAL_notification",
                    "message_id": null,
                    "metadata": {
                        "is_external": true
                    }
                },
                "input_channel": "telegram",
                "message_id": null
            },
            {
                "event": "user_featurization",
                "timestamp": 1671602339.5838938,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "use_text_for_featurization": false
            },
            {
                "event": "action",
                "timestamp": 1671602339.5838938,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_notification_to_user",
                "policy": "RulePolicy",
                "confidence": 1.0,
                "action_text": null,
                "hide_rule_turn": true
            },
            {
                "event": "bot",
                "timestamp": 1671602339.5838938,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "text": "This is a test!!",
                "data": {
                    "elements": null,
                    "quick_replies": null,
                    "buttons": null,
                    "attachment": null,
                    "image": null,
                    "custom": null
                }
            },
            {
                "event": "action",
                "timestamp": 1671602339.587904,
                "metadata": {
                    "model_id": "c8972d269a274335ba6436410b075686"
                },
                "name": "action_listen",
                "policy": "RulePolicy",
                "confidence": 1.0,
                "action_text": null,
                "hide_rule_turn": true
            }
        ],
        "latest_input_channel": "telegram",
        "active_loop": {},
        "latest_action": {
            "action_name": "action_listen"
        },
        "latest_action_name": "action_listen"
    },
    "messages": [
        {
            "recipient_id": "2079662765",
            "text": "This is a test!!"
        }
    ]
}

I’m using the bot in Telegram.

Rasa Version      :         3.4.0
Minimum Compatible Version: 3.0.0
Rasa SDK Version  :         3.4.0
Python Version    :         3.10.6
Operating System  :         Windows-10-10.0.22000-SP0

Thank you in advance!

Looking for the same issue. Bumped into your thread. Thanks for creating it. Looking forward for solution.

Thanks, Official DGCustomerFirst Survey

1 Like

Is there an already active Telegram session with id 2079662765?

Can you provide the debug log from Rasa showing external event, intent matching, dialog prediction, etc.?

Just to inform you that I changed from a telegram channel to a website channel.

I get the user id from the tracker.sender_id.

This is the log from the command: rasa run --enable-api --cors "*" --debug

2022-12-22 09:03:39 DEBUG    rasa.core.lock_store  - Issuing ticket for conversation 'a078b884d7534e2fae78a0df17e230b5'.
2022-12-22 09:03:39 DEBUG    rasa.core.lock_store  - Acquiring lock for conversation 'a078b884d7534e2fae78a0df17e230b5'.
2022-12-22 09:03:39 DEBUG    rasa.core.lock_store  - Acquired lock for conversation 'a078b884d7534e2fae78a0df17e230b5'.
2022-12-22 09:03:39 DEBUG    rasa.core.tracker_store  - Could not find tracker for conversation ID 'a078b884d7534e2fae78a0df17e230b5'.
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Starting a new session for conversation ID 'a078b884d7534e2fae78a0df17e230b5'.
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Action 'action_session_start' ended with events '[<rasa.shared.core.events.SessionStarted object at 0x000002349F774250>, ActionExecuted(action: action_listen, policy: None, confidence: None)]'.
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Current slot values:
        session_started_metadata: None
2022-12-22 09:03:39 DEBUG    rasa.core.actions.action  - Validating extracted slots:
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Default action 'action_extract_slots' was executed, resulting in 0 events:
2022-12-22 09:03:39 DEBUG    rasa.engine.runner.dask  - Running graph with inputs: {'__tracker__': <rasa.shared.core.trackers.DialogueStateTracker object at 0x000002349F776BF0>}, targets: ['select_prediction'] and ExecutionContext(model_id='aaa42f2f85ab4fee9fc69273b077dd62', should_add_diagnostic_data=False, is_finetuning=False, node_name=None).
2022-12-22 09:03:39 DEBUG    rasa.engine.graph  - Node 'rule_only_data_provider' running 'RuleOnlyDataProvider.provide'.
2022-12-22 09:03:39 DEBUG    rasa.engine.graph  - Node 'domain_provider' running 'DomainProvider.provide_inference'.
2022-12-22 09:03:39 DEBUG    rasa.engine.graph  - Node 'run_RulePolicy0' running 'RulePolicy.predict_action_probabilities'.
2022-12-22 09:03:39 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user text: EXTERNAL: EXTERNAL_notification | previous action name: action_listen
2022-12-22 09:03:39 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.
2022-12-22 09:03:39 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user intent: EXTERNAL_notification | previous action name: action_listen
2022-12-22 09:03:39 DEBUG    rasa.core.policies.rule_policy  - There is a rule for the next action 'action_notification_to_user'.
2022-12-22 09:03:39 DEBUG    rasa.engine.graph  - Node 'select_prediction' running 'DefaultPolicyPredictionEnsemble.combine_predictions_from_kwargs'.
2022-12-22 09:03:39 DEBUG    rasa.core.policies.ensemble  - Made prediction using user intent.
2022-12-22 09:03:39 DEBUG    rasa.core.policies.ensemble  - Added `DefinePrevUserUtteredFeaturization(False)` event.
2022-12-22 09:03:39 DEBUG    rasa.core.policies.ensemble  - Predicted next action using RulePolicy.
2022-12-22 09:03:39 DEBUG    rasa.core.processor  - Predicted next action 'action_notification_to_user' with confidence 1.00.
2022-12-22 09:03:39 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_notification_to_user'.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Policy prediction ended with events '[<rasa.shared.core.events.DefinePrevUserUtteredFeaturization object at 0x000002349F7746D0>]'.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Action 'action_notification_to_user' ended with events '[BotUttered('This is a test!!', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {}, 1671699822.01396)]'.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Current slot values:
        session_started_metadata: None
2022-12-22 09:03:42 DEBUG    rasa.engine.runner.dask  - Running graph with inputs: {'__tracker__': <rasa.shared.core.trackers.DialogueStateTracker object at 0x000002349F776BF0>}, targets: ['select_prediction'] and ExecutionContext(model_id='aaa42f2f85ab4fee9fc69273b077dd62', should_add_diagnostic_data=False, is_finetuning=False, node_name=None).
2022-12-22 09:03:42 DEBUG    rasa.engine.graph  - Node 'rule_only_data_provider' running 'RuleOnlyDataProvider.provide'.
2022-12-22 09:03:42 DEBUG    rasa.engine.graph  - Node 'domain_provider' running 'DomainProvider.provide_inference'.
2022-12-22 09:03:42 DEBUG    rasa.engine.graph  - Node 'run_RulePolicy0' running 'RulePolicy.predict_action_probabilities'.
2022-12-22 09:03:42 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 1] user intent: EXTERNAL_notification | previous action name: action_listen
[state 2] user intent: EXTERNAL_notification | previous action name: action_notification_to_user
2022-12-22 09:03:42 DEBUG    rasa.core.policies.rule_policy  - There is a rule for the next action 'action_listen'.
2022-12-22 09:03:42 DEBUG    rasa.engine.graph  - Node 'select_prediction' running 'DefaultPolicyPredictionEnsemble.combine_predictions_from_kwargs'.
2022-12-22 09:03:42 DEBUG    rasa.core.policies.ensemble  - Predicted next action using RulePolicy.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2022-12-22 09:03:42 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'.
2022-12-22 09:03:42 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'a078b884d7534e2fae78a0df17e230b5'.

Based on the log, there isn’t an active session with id a078b884d7534e2fae78a0df17e230b5 so you can’t send that session a message.

As far as I know, you can’t initiate a new session with an external event. If you look at the docs on external events, notice the use of “ongoing convesation” throughout the steps.

Most likely, you are using a session id for an inactive session.

1 Like