Send message to the BOT

Hi,

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.

Thank you

1 Like

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.

  1. Please follow the below steps to achieve your use case.
  2. Access the user provided input at on_user_message event by looking at data.message.
  3. Configure the custom logic to process the user input.
  4. Assign the output to data.message
  5. Send the data object back to the platform using sdk.sendBotMessage(data)

Hi @Subrahmanyam,

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) 

Thank you.

Hi Erges.

We are working on the example, we will update you.

Regards,
Yoga Ramya.

Any updates?

Thank you,

Erges

Hi @yogaramya.mendu,

Do you have updates about this topic?

Thank you.

Hi @erges_kokoshi,

Please accept our humble apologies for the delay.

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.
image

2- The intent ā€œgetBotKitDetailsā€ is trained with the utterance ā€œThis is botbuilder response from Botkitā€.
image

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ā€

on_user_message : function(requestId, data, callback) {

	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);
	}

image

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,

image

Kindly re-check the implementation at your end and let us know.

Regards,
Yoga Ramya.

Hi @yogaramya.mendu,

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.

Something weā€™re missing?

Thank you,

Erges