0
votes

Is it possible to send a variable to watson conversation?

This is simply what I'm trying to do. Get Slack Username Save the username as a context variable When the user talks to the chatbot it will say, Hello username without the need for a user input.

I have read about additional_context but I cannot seem to find anywhere how to use it. This is my function that processes the slack text before it goes to Watson conversation

msg._payload = msg.payload;
msg.payload = msg._payload.event.text; 
msg.additional_context = msg._payload.event.user
node.send(msg); // Send the message long to the next node

If I look in the debug node, the additional_context key returns the user Id correctly, But I don't know how to "fetch" it from inside a Conversation node.

Thanks in advance

1
You normally shouldn't be using node.send(msg) in function node, return msg is the usual way send the msg to the next node. - hardillb

1 Answers

0
votes

To add additional variable means to add the variable in the "context" part of the message request. When sending the POST message to Watson Assistant (Conversation) API add the variable as follow:

{ "input": { "text" : "Text the user typed." } "context" : { "username" : "user name", ...+all of the attributes of the context sent in the the last response from WA } }

Just remember - at the beginning of the conversation it is ok to send an empty context or a context containing only the username variable. However, as the conversation starts, the system sends its state in the context field, so it is important to send this context back in the next POST message request (as the system is state-less and the state is held in the context object). It is ok to add additional variables from node.js to this context though.

More info about POST message here: API documentation (23.10.2018)