Is there any way to send a message to the BOT based on the user input?
For example:
I retrieve the user message sent to the BOT
Process the response
Send the output to the bot so it can detect it as a user intent
I was looking at the documentation regarding sdk but there is no detailed information about it.
Hi @erges.kokoshi,
If the developer subscribes the botkit on builder to the event “onMessage”, the platforms notifies the botkit for both the events on_user_message (when user send a message to bot)and on_bot_message (when bot send a message to user).
When these events occur, the botkit receives the entire data object which includes the message sent by user/bot.This should be available at data.message.
Please follow the below steps to achieve your use case.
Access the user provided input at on_user_message event by looking at data.message.
Configure the custom logic to process the user input.
Assign the output to data.message
Send the data object back to the platform using sdk.sendBotMessage(data)
Can you please give an example of what you indicated in your response?
What I did is:
1- Capture user input using the following ( I am using a script node) :
context.session.BotUserSession.lastMessage.messagePayload.message.body;
2 - Remove from the input ( sentence sent to the bot ) words based on their position
What I want to do is:
3 - Send to the BOT the output sentence on step 2 as it is the user typing something so the BOT .
Here is an example:
The user input is: “Thank you. Can you show me my PTO balance?”
The sentence I want to send to the BOT is "Can you show me my PTO balance" so it can trigger an
intent(if any detected by the BOT)
Kindly find the following example implementation for your scenario.
1- We have a dialog task “getBotKitDetails” in a bot which has two entity nodes and a message node in it.
2- The intent “getBotKitDetails” is trained with the utterance “This is botbuilder response from Botkit”.
3- If a user says " This is botbuilder platform", then in the botKit respective js file, in the “on_user_message” function, we have written the following code to manipulate the sentence to “This is botbuilder response from Botkit”
if(data.message === "This is botbuilder platform"){
var a = data.message;
var b = a.replace("platform", "response from Botkit");
data.message = b;
return sdk.sendBotMessage(data, callback);
}
The sdk.sendBotMessage(data, callback) method is used to send the data to the bot and the bot will process it. If it is a matched utterance, then it would return the dialog task flow.
4- Please find the below screenshot where the user utterance is processed with the code written in the Botkit respective bot js file and returned the appropriate utterance to the bot. Hence, the bot is asking for the entity value after recognizing the utterance,
Kindly re-check the implementation at your end and let us know.
Thank you for your response. Is there a way that the same result can be achieved not modifying the botkit?
I think this solution will be limited by the fact that when a new BOTKIT release will be available(like recently happened from v6 to v7) we will need to update the new BotKit so to include the custom code.
Can the data object and sdk be used in a script node without touching the BotKit code?
Tell me if I need to open a new topic for the following:
1- We have configured the onConnect event to display a certain message when the chat window gets opened.
2- We created a js file where we have different functions that we would like to use. Here it comes the problem. As soon as we import that file to have it available the onConnect event stops working.