Get data as slots from logged in users

Hey so I think I am running into a conceptual issue here, I want to fill certain slot values with currently logged in user’s details by fetching them through my database. I am not sure will I be using sender_id to match with database’s uid or what?

How can we use sender_id to fetch details of currently logged-in user? What actually is sender_id? @erohmensing

Unless your channel manages it, the sender_id is generated automatically by rasa and is unique per convo session. For example, the Slack connector uses the user event to set the sender_id:

1 Like

okay sounds about right. But should I be making an api call to my app/website or what exactly? could you please maybe provide an instance?

You can take a look at these docs: Custom Connectors On implementing a custom connector, they tell you the required methods.

It’s actually your channel (so website/app) that will be making API calls to Rasa. So, once you have defined your custom connector, you put Rasa’s webhook address in the right place in your app/website. If you look at the Slack example, or the Rest example, you’ll see that pattern in both cases.

okay. I am a little confused here. I want to greet my logged-in user with his/her name by querying through database or probably using an api? Can you suggest me the most elegant way to achieve it?

I went through a bunch of forum posts but couldn’t find a step by step procedure for achieving it. And the possible ways that rasa provides

In that case, all you want is a custom action. Actions A custom action can do whatever you program it to do, including querying a database. Possibly you haven’t found what you’re looking for because you’ve been looking at channels, when really you want a custom action. If you, in addition to that, want the sender_id to match that name, that’s when you need to look at the channel side of things.

1 Like

You’ll find plenty of examples on the forum about custom actions, or you can look at these demo bots’ action code:

Here’s one with a customized greeting action that takes name into account (among other things):

1 Like

Okay great. I am querying a database and using postman to test the sender_id to match my logged-in user’s id. Now what I need to discover is that can I make my app/website send current logged-in user’s id as sender_id when using (tracker.current_state())[“sender_id”] inside my custom action?

great help, thankyou so much.

can I make my app/website send current logged-in user’s id as sender_id when using (tracker.current_state())[“sender_id”] inside my custom action?

You cannot “change” the sender_id inside a custom action, you can only access it. If you want to set the sender ID, that needs to happen on the channel side.

Since you are using Postman, I’m assuming you are calling the Rest webhook. In this case, you would use the intended sender_id in the payload you send to the webhook.

Does that make sense?