0
votes

Using the below code to generate an event to the bot thru directline.

<!DOCTYPE html>
    <html>
    <head>
        <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
    </head>
    <body>
        <div>
            <div id="bot" />
        </div>
        <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
        <script>
            var user = {
                id: 'user-id',
                name: 'user name'
            };
            var botConnection = new BotChat.DirectLine({
                token: 'MYTOKENHERE',
                user: user
            });
            BotChat.App({
                user: user,
                botConnection: botConnection,
                bot: { id: 'bot-id', name: 'bot name' },
                resize: 'detect'
            }, document.getElementById("bot"));
            botConnection
                .postActivity({
                    from: user,
                    name: 'requestWelcomeDialog',
                    type: 'event',
                    value: ''
                })
                .subscribe(function (id) {
                    console.log('"trigger requestWelcomeDialog" sent');
                });
        </script>
    </body>
</html>

I have code to handle any event/message which reach from the bot. When I type hi or any messages it will work. But not automatically while I load the chatbot as a conversationupdate activity as promised by MS bot framework documentation. Can any one please help.

2
Marking the solution as accepted serves the greater Stack Overflow community and anyone with a similar question. If you feel my answer was sufficient, please "accept" it. If not, let me know how else I can help! - tdurnford

2 Answers

0
votes

For starters, it looks like you are using Web Chat v3, which is depreciated and no longer supported. I would recommend switching to Web Chat v4, especially if you are just getting started. Note, Web Chat v4 does work with v3 Bots. Take a look at the Web Chat Samples to get started with v4.

Also, I'm assuming you're talking about the Welcome Message not being sent properly in Web Chat. If that's the case, take a look at this GitHub answer. It discusses how to properly send a Welcome Message in Web Chat. Some of the principles discussed in the answer still apply to Web Chat v3 if you don't intend to switch to v4.

0
votes

You have to handle the request on your bot code. Check for the "requestWelcomeDialog" like so. This should be in your MainDialog.

   protected override async Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.Name == "requestWelcomeDialog")
            {
                //send activity here
            }
        }