OVERVIEW
In this blog, I’ll show you about one of the unique but the most important topic of the Rasa chatbot which makes it multi-tasking to handle multiple conversations at a time. So what I am discussing is known as the Session ID or the Conversation ID, which is a unique identification ID for each user which will help the rasa chatbot to recognize that who is texting the bot, what reply it has to give to the which user, etc. That’s all just because of this single but unique identification Id know as a session ID or conversation ID.
Now, let’s see how to generate the conversation for each unique user. Let’s get started now.
Generating Session ID
To generate or get the session ID for each conversation, I will create a short conversation which is as shown here,
User: May i know what is my conversation id
Bot: The conversation id is 5d24a6dbf2684897aed420465deffda1
So, this is a short conversation that I’ll have with my bot and my bot will tell me the unique session ID in return. Now let’s create this conversation into the rasa project and let’s understand how to get the unique session ID. For that make the changes into the existing Rasa project in such a way,
nlu.md
## intent:ask_id - tell me the conversation id - what's my conversation id - tell me session id - may i know what is my session id - What is the ID of this conversation?
Here, I have create a new intent which is a user input to ask for the conversation ID.
actions.py
class ActionSessionId(Action): def name(self) -> Text: return "action_session_id" async def run( self, dispatcher, tracker: Tracker, domain: Dict[Text, Any] ) -> List[Dict[Text, Any]]: conversation_id=tracker.sender_id dispatcher.utter_message("The conversation id is {}".format(conversation_id)) return []
In the actions.py script, I’ve added a new action class where I’ve fetched the session ID using the tracker. Rasa itself takes care of this session ID, so we don’t have to generate it manually. That is the reason which makes it multi-tasking more user friendly.
conversation_id=tracker.sender_id dispatcher.utter_message("The conversation id is {}".format(conversation_id))
This code is used to get the unique session ID and to display it to the user in return with session ID.
domain.yml
intents: - ask_id: triggers: action_session_id actions: - action_session_id
Here, instead of calling the stories, I just triggered the custom action directly with respect to the intent that we created to ask for the session/conversation ID.
You can also check this video for more clarity,
After you have added all the codings and data to the project, it’s time to train the model and test it with the following commands,
rasa train rasa x and also run action server in seperate terminal, rasa run actions
and once the model is trained and Rasa UI is running you can talk your bot to check the conversation id, which will look something like this.
You can download the full code here,
DOWNLOAD FULL CODE HERE
Also, as I said this conversation ID is a unique ID so for every user talking to the bot will have a unique session ID. To explain this here you can see the conversation ID for different users who talked to the bot.
Time to wrap up now. Hope you liked our content on How to generate the session id for every user. See you in our next blog, thanks for reading our blog and do leave a comment below to help us improve the content to serve you all of our experience with you. Stay tuned with us for more Rasa Chatbot contents.
Also check out our other playlist Rasa Chatbot, Internet of things, Docker, Python Programming, etc.
Become a member of our social family on youtube here.
hello, how can i use rasa x conversation id in rasa because i am getting default value as a session id from rasa and i need to use rasa x conversation id as you shown in your video.
Can you please elaborate, coz I didn’t get your question?