How can I get a conversation_id so I run an Action via POST from an App

Hello, I will like to directly run an action from a .NET server to the RASA server via POST. Basically I will like to get the conversation_id of a user and send it to a third party server. Once the 3rd party server executes an action, it will perform an http POST back to RASA so it can execute a function.

Can I do this? Is this bad practice? Can this only happen at the action.py lvl? Just started on RASA yesterday and I am not sure how to proceed.

http://localhost:5005/conversations/{conversation_id}/execute

{ “name”: “action_somename”, “policy”: “string”, “confidence”: 0.987232 }

If the conversation_id in the request does not exist, a new “conversation” with that id will be created inside Rasa. So, you can basically set and manage the conversations ids yourself. Does that help?

Hello @Tanja!

I am still confused by where is the conversation_id gets set. I created a simple websockets powered chat front end that hard codes the session_id and conversation_id for testing:

socket.on('connect', function(msg) {
    socket.emit('session_request', 
        ({'session_id': 12345, 'conversation_id' : 67890 })
    );
});

the credentials.yml looks like this:

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered
  session_persistence: true

After chatting through the frontend(websockets), I wanted to retrieve a conversations tracker:

http://localhost:5005/conversations/67890/tracker

The response is this:

{
    "sender_id": "67890",
    "slots": {},
    "latest_message": {
        "intent": {},
        "entities": [],
        "text": null,
        "message_id": null,
        "metadata": null
    },
    "latest_event_time": 1571671551.5727872849,
    "followup_action": null,
    "paused": false,
    "events": [
        {
            "event": "action",
            "timestamp": 1571671551.5727872849,
            "name": "action_listen",
            "policy": null,
            "confidence": null
        }
    ],
    "latest_input_channel": null,
    "active_form": {},
    "latest_action_name": "action_listen"
}

Why does the conversation_id becomes the sender_id?

If I change the get to use the sender_id instead of the converstion_id: http://localhost:5005/conversations/12345/tracker I actually get the tracker that I am looking for: Is sender_id and conversation_id the same thing?

{
    "sender_id": "12345",
    "slots": {},
    "latest_message": {
        "intent": {
            "name": "mood_unhappy",
            "confidence": 0.9948384166
        },
        "entities": [],
        "intent_ranking": [
           .....
        ],
        "text": "sad"
    },
    "latest_event_time": 1571671750.9962654114,
    "followup_action": null,
    "paused": false,
    "events": [
        {
            "event": "action",
            "timestamp": 1571671396.7521972656,
            "name": "action_listen",
            "policy": null,
            "confidence": null
        },
        {
            "event": "user",
            "timestamp": 1571671396.8155121803,
            "text": "Hello",
            "parse_data": {
                "intent": {
                    "name": "greet",
                    "confidence": 0.9864999652
                },
                "entities": [],
                "intent_ranking": [
                    .....
                ],
                "text": "Hello"
            },
            "input_channel": "socketio",
            "message_id": "269b550cc38743f9997f4c60cb11acbe",
            "metadata": null
        },
        {
            "event": "action",
            "timestamp": 1571671396.9251480103,
            "name": "utter_greet",
            "policy": "policy_0_MemoizationPolicy",
            "confidence": 1.0
        },
        {
            "event": "bot",
            "timestamp": 1571671396.9251606464,
            "text": "Hey! How are you?",
            "data": {
                "elements": null,
                "quick_replies": null,
                "buttons": null,
                "attachment": null,
                "image": null,
                "custom": null
            },
            "metadata": {}
        },
        {
            "event": "action",
            "timestamp": 1571671396.9300782681,
            "name": "action_listen",
            "policy": "policy_0_MemoizationPolicy",
            "confidence": 1.0
        },
        {
            "event": "user",
            "timestamp": 1571671750.4503774643,
            "text": "sad",
            "parse_data": {
                "intent": {
                    "name": "mood_unhappy",
                    "confidence": 0.9948384166
                },
                "entities": [],
                "intent_ranking": [
                   ......
                ],
                "text": "sad"
            },
            "input_channel": "socketio",
            "message_id": "474b785331084d21a55248d44e526d97",
            "metadata": null
        },
        {
            "event": "action",
            "timestamp": 1571671750.9833481312,
            "name": "action_joke",
            "policy": "policy_0_MemoizationPolicy",
            "confidence": 1.0
        },
        {
            "event": "bot",
            "timestamp": 1571671750.9833676815,
            "text": "Chuck Norris has never been accused of murder because his roundhouse kicks are recognized as "acts of God."",
            "data": {
                "elements": null,
                "quick_replies": null,
                "buttons": null,
                "attachment": null,
                "image": null,
                "custom": null
            },
            "metadata": {}
        },
        {
            "event": "action",
            "timestamp": 1571671750.9904024601,
            "name": "utter_did_that_help",
            "policy": "policy_0_MemoizationPolicy",
            "confidence": 1.0
        },
        {
            "event": "bot",
            "timestamp": 1571671750.9904193878,
            "text": "Did that help you?",
            "data": {
                "elements": null,
                "quick_replies": null,
                "buttons": null,
                "attachment": null,
                "image": null,
                "custom": null
            },
            "metadata": {}
        },
        {
            "event": "action",
            "timestamp": 1571671750.9962654114,
            "name": "action_listen",
            "policy": "policy_0_MemoizationPolicy",
            "confidence": 1.0
        }
    ],
    "latest_input_channel": "socketio",
    "active_form": {},
    "latest_action_name": "action_listen"
}

Yes, sender_id and conversation_id are the same thing. It used to be called sender_id, but then we renamed it to conversation_id. However, it seems like, we forgot some places.

1 Like

@Tanja, I am confused as to why I can only retrieve the conversation tracker when i send it the session_id and not the conversation_id/sender_id. When the socket connects I pass it the following object:

      socket.on('connect', function(msg) {
        socket.emit('session_request', 
          ({'session_id': 12345, 'conversation_id' : 67890 })
        );
      });

On my previous response dump the conversation_id of 67890 does not return the correct tracker. The session_id does.

Regards

Just check the code: If you are using session, then the conversation_id is the session_id (means that it is a new conversation, as soon as the session expires).

If you are not using sessions, than it will use the sid. .

Hi @Tanja,

Yes, sender_id and conversation_id are the same thing. It used to be called sender_id , but then we renamed it to conversation_id .

That’s great! I messa round for a bunch of hours when I finally your statement that I confirmed with a simple test:

First of all I talk with a bot with sender = "Giorgio"

curl localhost:5005/webhooks/rest/webhook -d '{ "sender": "Giorgio", "message": "hi" }'

and afterward I call the /prediction endpoint, just as an example, passing “Giorgio” as conversation_id

curl -s -X POST localhost:5005/conversations/Giorgio/predict

getting expected results ( see full payload answer of curl requests at the end of this post):

Notes:

  • in the last call the sender is in attribute with name sender_id,
  • that is NOT conversation_id (as documentation states)
  • that is NOT sender (as the webhook endpoint requires)
  • that is NOT recipient_id (as the webhook endpoint reply)
  • that is NOT session_id (as I read somewhere in documentation, if I’m not wrong)

So I’m happy that this holy ID has 5 different names that identify the same stuff :sweat_smile: That’s important for the application need to send “push” message to sender_id, calling /conversations/<conversation_id>/trigger_intentendpoint to trigger a push message in case of external events.

Nice! but…

However, it seems like, we forgot some places.

Yes. I agree with the closed issue consolidate sender_id and conversation_id #4683:

My modest suggestions:

  1. quick & dirty solution is to solve the topic just with big visible annotation boxes in the documentation, here and there on user guide pages, REST API doc page, etc., just stating in large print:

sender === sender_id ==== conversation_ID === recipient_id (=== session_id) :wink:

  1. honestly the API interface would be “consolidated” at least at the external HTTP interface level. I understand the backward compatibility needs. A solution is to deprecate (in documentation) the old attribute names (as “sender”), still accepting them, and suggesting to use a unique name (e.g. conversation_id).

Make sense for you? I’m missing something?

Sorry for long post. Thanks / giorgio


$ curl -s localhost:5005/webhooks/rest/webhook -d '{ "sender": "Giorgio", "message": "hi" }' | json
[
    {
        "recipient_id": "Giorgio",
        "text": "hey"
    },
    {
        "buttons": [
            {
                "payload": "/mood_great",
                "title": "great"
            },
            {
                "payload": "/mood_unhappy",
                "title": "sad"
            }
        ],
        "recipient_id": "Giorgio",
        "text": "How are you?"
    }
]

$ curl -s -X POST localhost:5005/conversations/Giorgio/predict |json
{
    "confidence": 0.9853241444,
    "policy": "policy_0_TEDPolicy",
    "scores": [
        {
            "action": "utter_greet",
            "score": 0.9853241444
        },
        {
            "action": "utter_iamabot",
            "score": 0.0041449759
        },
        {
            "action": "utter_did_that_help",
            "score": 0.0024251365
        },
        {
            "action": "utter_goodbye",
            "score": 0.0021894691
        },
        {
            "action": "utter_cheer_up",
            "score": 0.0020371093
        },
        {
            "action": "utter_noworries",
            "score": 0.0012032713
        },
        {
            "action": "action_session_start",
            "score": 0.0007067497
        },
        {
            "action": "utter_happy",
            "score": 0.0007019339
        },
        {
            "action": "action_restart",
            "score": 0.0006773554
        },
        {
            "action": "action_default_fallback",
            "score": 0.000589791
        },
        {
            "action": "action_back",
            "score": 0.0
        },
        {
            "action": "action_deactivate_form",
            "score": 0.0
        },
        {
            "action": "action_default_ask_affirmation",
            "score": 0.0
        },
        {
            "action": "action_default_ask_rephrase",
            "score": 0.0
        },
        {
            "action": "action_listen",
            "score": 0.0
        },
        {
            "action": "action_revert_fallback_events",
            "score": 0.0
        },
        {
            "action": "utter_how_are_you",
            "score": 0.0
        }
    ],
    "tracker": {
        "active_form": {},
        "events": [
            {
                "confidence": null,
                "event": "action",
                "name": "action_session_start",
                "policy": null,
                "timestamp": 1588440894.6446385
            },
            {
                "event": "session_started",
                "timestamp": 1588440894.6446514
            },
            {
                "confidence": null,
                "event": "action",
                "name": "action_listen",
                "policy": null,
                "timestamp": 1588440894.6446688
            },
            {
                "event": "user",
                "input_channel": "rest",
                "message_id": "1557eff7286f44268920b8fb83cd3797",
                "metadata": {},
                "parse_data": {
                    "entities": [],
                    "intent": {
                        "confidence": 0.9912492037,
                        "name": "greet"
                    },
                    "intent_ranking": [
                        {
                            "confidence": 0.9912492037,
                            "name": "greet"
                        },
                        {
                            "confidence": 0.0024676742,
                            "name": "affirm"
                        },
                        {
                            "confidence": 0.0020308082,
                            "name": "deny"
                        },
                        {
                            "confidence": 0.0014053768,
                            "name": "bot_challenge"
                        },
                        {
                            "confidence": 0.0012757968,
                            "name": "mood_unhappy"
                        },
                        {
                            "confidence": 0.0007220268,
                            "name": "goodbye"
                        },
                        {
                            "confidence": 0.0005345532,
                            "name": "thank"
                        },
                        {
                            "confidence": 0.0003145098,
                            "name": "mood_great"
                        }
                    ],
                    "text": "hi"
                },
                "text": "hi",
                "timestamp": 1588440894.853342
            },
            {
                "confidence": 1.0,
                "event": "action",
                "name": "utter_greet",
                "policy": "policy_1_MemoizationPolicy",
                "timestamp": 1588440894.8554208
            },
            {
                "data": {
                    "attachment": null,
                    "buttons": null,
                    "custom": null,
                    "elements": null,
                    "image": null,
                    "quick_replies": null
                },
                "event": "bot",
                "metadata": {},
                "text": "hi",
                "timestamp": 1588440894.8554251
            },
            {
                "confidence": 1.0,
                "event": "action",
                "name": "utter_how_are_you",
                "policy": "policy_1_MemoizationPolicy",
                "timestamp": 1588440894.857363
            },
            {
                "data": {
                    "attachment": null,
                    "buttons": [
                        {
                            "payload": "/mood_great",
                            "title": "great"
                        },
                        {
                            "payload": "/mood_unhappy",
                            "title": "sad"
                        }
                    ],
                    "custom": null,
                    "elements": null,
                    "image": null,
                    "quick_replies": null
                },
                "event": "bot",
                "metadata": {},
                "text": "How are you?",
                "timestamp": 1588440894.8573668
            },
            {
                "confidence": 1.0,
                "event": "action",
                "name": "action_listen",
                "policy": "policy_1_MemoizationPolicy",
                "timestamp": 1588440894.8591037
            },
            {
                "event": "user",
                "input_channel": "rest",
                "message_id": "2751ca8ffb164a8a9a5284ef5880afc9",
                "metadata": {},
                "parse_data": {
                    "entities": [],
                    "intent": {
                        "confidence": 0.9912492037,
                        "name": "greet"
                    },
                    "intent_ranking": [
                        {
                            "confidence": 0.9912492037,
                            "name": "greet"
                        },
                        {
                            "confidence": 0.0024676742,
                            "name": "affirm"
                        },
                        {
                            "confidence": 0.0020308082,
                            "name": "deny"
                        },
                        {
                            "confidence": 0.0014053768,
                            "name": "bot_challenge"
                        },
                        {
                            "confidence": 0.0012757968,
                            "name": "mood_unhappy"
                        },
                        {
                            "confidence": 0.0007220268,
                            "name": "goodbye"
                        },
                        {
                            "confidence": 0.0005345532,
                            "name": "thank"
                        },
                        {
                            "confidence": 0.0003145098,
                            "name": "mood_great"
                        }
                    ],
                    "text": "hi"
                },
                "text": "hi",
                "timestamp": 1588441827.8472962
            },
            {
                "confidence": 0.9858503342,
                "event": "action",
                "name": "utter_greet",
                "policy": "policy_0_TEDPolicy",
                "timestamp": 1588441827.850348
            },
            {
                "data": {
                    "attachment": null,
                    "buttons": null,
                    "custom": null,
                    "elements": null,
                    "image": null,
                    "quick_replies": null
                },
                "event": "bot",
                "metadata": {},
                "text": "hey",
                "timestamp": 1588441827.8503537
            },
            {
                "confidence": 0.9982337952,
                "event": "action",
                "name": "utter_how_are_you",
                "policy": "policy_0_TEDPolicy",
                "timestamp": 1588441827.853193
            },
            {
                "data": {
                    "attachment": null,
                    "buttons": [
                        {
                            "payload": "/mood_great",
                            "title": "great"
                        },
                        {
                            "payload": "/mood_unhappy",
                            "title": "sad"
                        }
                    ],
                    "custom": null,
                    "elements": null,
                    "image": null,
                    "quick_replies": null
                },
                "event": "bot",
                "metadata": {},
                "text": "How are you?",
                "timestamp": 1588441827.853198
            },
            {
                "confidence": 0.9818285704,
                "event": "action",
                "name": "action_listen",
                "policy": "policy_0_TEDPolicy",
                "timestamp": 1588441827.8560057
            }
        ],
        "followup_action": null,
        "latest_action_name": "action_listen",
        "latest_event_time": 1588441827.8560057,
        "latest_input_channel": "rest",
        "latest_message": {
            "entities": [],
            "intent": {
                "confidence": 0.9912492037,
                "name": "greet"
            },
            "intent_ranking": [
                {
                    "confidence": 0.9912492037,
                    "name": "greet"
                },
                {
                    "confidence": 0.0024676742,
                    "name": "affirm"
                },
                {
                    "confidence": 0.0020308082,
                    "name": "deny"
                },
                {
                    "confidence": 0.0014053768,
                    "name": "bot_challenge"
                },
                {
                    "confidence": 0.0012757968,
                    "name": "mood_unhappy"
                },
                {
                    "confidence": 0.0007220268,
                    "name": "goodbye"
                },
                {
                    "confidence": 0.0005345532,
                    "name": "thank"
                },
                {
                    "confidence": 0.0003145098,
                    "name": "mood_great"
                }
            ],
            "text": "hi"
        },
        "paused": false,
        "sender_id": "Giorgio",
        "slots": {}
    }
}