Search code examples
javascriptbotframeworkbotschatbotweb-chat

How can i send a automatic message to the bot at the beginning (Webchat V4 + Javascript)


im trying to set up a bot with the Microsoft Bot Framework. For the communication interface im using the Webchat V4 (https://github.com/microsoft/BotFramework-WebChat). I want a message to be sent to the bot once the webchat is loaded on the website. The message can be hidden or seen in the chat window (hidden would be better tho). Can i implement this and if so how?

Im using the javascript version of the Webchat by the way.


Solution

  • The BotFramework-WebChat repo has a sample, 04.api/a.welcome-event, that demonstrates how to set this up.

    In short, when Web Chat connects, an event is emitted from Web Chat to the bot. When the bot receives this particular event, the "Welcome Message" from the bot is sent back to the client and is displayed to the user.

    As for hiding a message, there is no way to do this. If you don't want the message to display immediately, then don't use the above and, instead, explore some of the other Web Chat store actions and determine a client/bot setup that works for you.

    For instance, you could

    • Put a timer on the welcome message so it sends n seconds after connecting (or sends n seconds after connecting if no message is first sent from the user)
    • Sends a welcome message only after a message is received by the bot (primarily a bot implementation but you could utilize Web Chat to further customize)
    • (If there is some page interaction) you could dispatch a window event that sends an event to the bot which then displays the message.

    Hope of help!