Managing Conversation Context via My own Rest Controller - Need Help!

Hi, I have been playing with simple forms and NLP of Rasa. And the simple things works when we test it with rasa shell.

Right now I am on the latets rasa version.

However I am wondering if we we can manage the bot conversation from our own front end widget. From documentation I think in order to achieve that I will need to use HTTP APIs exposed by Rasa. However I am not fully sure of how to manage a full conversation context with it back and forth.

I have created a form that asks user 3 or 4 inputs. when the user submits his message from the chat windows, it sends the message to my Rest Controller. Now I am bit stuck here and would need some help.

  1. I see we have an endpoint /model/parse. When I use this I can send the user message to Rasa core for detecting the intents / entities. And i can see that working from the response. So for example if the user message had two entities out of three, I can see in the response that Rasa detects 2 entities. But it does not mentions anything about the third entity being missing. Nor do I see in the response the prompt I had added for the missing slot via utter_ask_thirdEntity.

  2. I see that we have another end point http://localhost:5005/webhooks/rest/webhook. When I call this end point with the same user message, I see that Rasa is able to detect the entities and in this case it return the message I had configured in domain.yml to ask for the missing slot. However in it’s response Rasa does not returns any info about the detected intent and entities.

Also, I am not clear where and how Rasa is maintaining the context. So assuming that I combine both 1 and 2 above to get the detected intent/entities (by 1) and then response configured for asking slot info (by 2), and then I play back the response from 2 to my front end. and then the user will supply the answer for it. when the answer again comes back to my Rest Controller and now my Rest Controller has to again call Rasa endpoints how to specify the conversation state / context in these ends points ?

Do I need to use another end point or points exposed by Rasa Or is there a different way to achieve this ?

Any example bot ot tutorial explaining this ?

I would really appreciate your help with this.

@utsuk.prani Could you please elaborate what you’re wanting to achieve? On first glance it looks like that you’re trying to re-implement some parts of Rasa Open Source while re-using some others. Have you checked out the forms documentation?

But it does not mentions anything about the third entity being missing.

If it wasn’t in the message or it wasn’t detected by the entity extractor then Rasa NLU (the part of Rasa Open Source which parses the messages to get intents / entities) won’t know that it’s “missing”. It can only see what’s there.

. Nor do I see in the response the prompt I had added for the missing slot via utter_ask_thirdEntity

/model/parse really just processes the message to get intents and entities. There is no conversation state involved at all. Handling conversation state (what the assistant should do in which situation) is handled by Rasa Core.

I see that Rasa is able to detect the entities and in this case it return the message I had configured in domain.yml to ask for the missing slot. However in it’s response Rasa does not returns any info about the detected intent and entities.

The rest channel returns the plan assistant answers but doesn’t include internal details (intent, entities, slots). You use e.g. this endpoint to retrieve the full conversation context of a conversation.

I’d recommend to do one of the initial tutorials in order to understand how the components play together:

Thanks for sharing the links @Tobias_Wochinger. My aim is to have the below flow:

  1. From my custom front end (chat widget) the user will chat with the bot. So basically capture all the slot info from here.
  2. When the user hits send, the message will come my Rest Controller.
  3. From my rest controller I want to utilize Rasa capabilities to perform NLU and be able to use the dialog (conversation) management features.
  4. Once my rest controller gets Rasa response, I want to play back the results to my front end. 4.a - If all slots are receive, my rest controller will needs to call some other external rest apis to get results. and then these results will go back to my front end as response. 4.b - if any slot is missing, i want to be able to understand that from Rasa response and playback to my front end to seek that slot info.

So I created a simple form as rasa samples explain where I control seeking of the 4 slots I need. and it works work as i test it from rasa shell.

Now I wanted to implement the same flow of logic from my own front end which sends user input to Rest Controller as explained above.

I was trying to establish the best flow in terms of how interaction will look like between 1. my front end to Rest Controller. 2. then from Rest Controller to Rasa (conversation / context mgmt) until I get all required slots from the user. 3. finally calling the external rest with all slots captured to perform external action.

From what I have understood so far I need to go like this. any suggestions for improving the flow or implementing best practice recommended by Rasa are welcome.

  1. User sends message 1 from my front end to Rest Controller (/webhooks/rest/webhook).
  2. My rest controller will call the rasa REST endpoint with message like below:

    {“sender”: “userId”, “message”: “need info about slot1_value” }

  3. I have understood that the sender (userId) here can be used as the unique conversation_id that can be used to track the ongoing conversation via the tracker.
  4. Also the response of call to /webhooks/rest/webhook is as per the responses defined in domain.yml. So based on my slot definition and form, rasa will respond back as per uone of my defined utter_ask_*.
  5. I can playback this response to the front end or perform any logic in between in my rest controller.
  6. next time when the user again sends a message 2. say giving value of the slot 2, my front end will again send the message to Rest Controller.
  7. this time, my Rest controller will perform 2 things. First it will again call (/webhooks/rest/webhook) to try n detect user intent / entities. Second, it will call /conversations/userId/tracker to get the state of current conversation based on the conversation_id.
  8. this will continue to happen till in my Rest Controller I determine via (/conversations/userId/tracker), that I have received all the slots from the user.
  9. Now I can call external api with all slots to fetch desired results and display back results to my front end.

So basically as i see it i need to use two rasa endpoints to manage the dialog via my rest controller -

  1. /webhooks/rest/webhook
  2. /conversations/userId/tracker

I’m not sure about the purpose of your RestController. It seems like it’s duplicating behavior Rasa Open Source already does. For example 7 & 8 are already performed by forms. I think what you need is actually a custom connector + some forms / custom actions.