Hi… Here I am trying to send some data wanting to be set in the slots. data is sent from a separate API.
- In case you mean you want to SEND data from an API to the bot:
You can send entities with a payload like /inform{'username': user.username}
. Of course, the entity will need to Auto-fill the slot.
- In case you mean you want to RECIEVE data from an API:
Call that API in a Custom Action, and at the end of the run()
method, return [SlotSet('username', user['username'])]
for example.
You can do it in custom action.
from rasa_sdk.events import SlotSet
...
class CustomAction(Action):
...
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
...
return [SlotSet('some_slot', 'some_value')]
@ChrisRahme Thank you for the reply, I am following the first case of your answer which is to SEND data from an API to the bot, Since I am new to Rasa Framework It would be great if you can elaborate on the answer by considering the above context.
Please NOTE that…
-I need to set multiple slots from a single payload
-I have Installed Rasa
-Currently using Two Commands - rasa shell and rasa run actions.
Thank you
@ivan.dmi Thanks for the reply and this will surely help me in my future work. and my requirement is to SEND data from an API to the bot. It is great if you can elaboratively explain to me, what would be the URL to do the POST call and How to include multiple slots that are to be set.
moreover, you can refer to my reply to ChrisRahme (above)
Thank you.
No problem, if I’m not clear don’t be afraid to ask for more explanations
To send a message to the Rasa Server, you will need to send a POST request containing the message (in this case, more particularly, payload), and the sender ID. You can test this out via Postman like so:
Before that, you have to set up the Action endpoint in endpoints.yml
by adding the following:
action_endpoint: # Communication via HTTP REST
url: "http://localhost:5055/webhook"
The URL for the POST request is http://localhost:5005/webhooks/rest/webhook
, or, if deployed on a server, http://194.126.17.114/webhooks/rest/webhook
for example.
Now, you just need to get the sender ID somehow. If you have a chatting application or a user authentication process on the same page as your API, it’s easy, just use the same variable
You can set multiple slots!
Just send /intentname{'firstslot': firstvalue, 'secondslot': secondvalue}
etc.
@ChrisRahme Thank you very much for the informative reply. Currently, I am trying out with Postman.
I will attach a Screenshot of a single slot set that I was trying after seeing another forum post (Is there any way to set Slot by API not by action) which didn’t work out for me.
Here I have used only Content-type —> application/json headers
I have configured the endpoints.yml exactly as you stated above. and I am not using along with a Sender ID I just wanted to try out with the initial session created after the command Rasa Shell I am working on my college research project so I am using the Framework to work with the initial session.
If it is required to use sender ID will you please let me have an idea to work on my basic purpose?
Here you should POST to /conversations/<conversation_id>/events
instead of /webhooks/rest/webhook
.
I’ve never tried it, but try to fix the URL and do it again
Sorry, I don’t think I understand what you mean by “work on my basic purpose”.
But you need a sender ID (or conversation ID for the 2nd option). It makes sense because you want to set a slot in a conversation, which has an ID (sender ID and conversation ID are the same).
@ChrisRahme yes I did try with the exact way of the forum post as well using /conversations/<sender_id>/tracker/events
. it seems your suggestion is a bit different.
“work on my basic purpose”, what I meant is, I am not managing sessions in my project.
as per your previous suggestion, where to use the sender ID? and can you elaborate how a correct POST request looks like? along with a slot setting payload
Here are some examples of objects:
{sender: "Chris", message: "Hello"}
{sender: "WebUser", message: "/greet"}
{sender: "GS34E33EAH3G4432GBE6", message: "/greet{'name': 'Chris'}"}
{sender: "42", message: "/greet{'name': 'Chris', 'age': '23', 'country': 'Lebanon'}"}
For a JavaScript example of a POST request, please see this code at line 192 (send()
function): https://github.com/ChrisRahme/fyp-webapp/blob/main/assets/js/script.js#L192
Here, the sender ID is randomly generated as a UUIDv4 when the webpage loads (line 19).