0
votes

I have created a QnA maker Bot. Now I would like to wish the user with a greeting when the conversation starts. I saw in a link that this can be achieved using Conversation update, I have added the following code in QnABot.cs which comes inside the Bots folder

private async Task HandleSystemMessage(Activity message)
        {
            if (message.Type == ActivityTypes.DeleteUserData)
            {
                // Implement user deletion here
                // If we handle user deletion, return a real message
            }
            else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
                {
                    ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));

                    var reply = message.CreateReply();

                    reply.Text = "Hello and Welcome ";

                    await client.Conversations.ReplyToActivityAsync(reply);
                }
            }
            else if (message.Type == ActivityTypes.ContactRelationUpdate)
            {
                // Handle add/remove from contact lists
                // Activity.From + Activity.Action represent what happened
            }
            else if (message.Type == ActivityTypes.Typing)
            {
                // Handle knowing tha the user is typing
            }
            
        }

Is this right place to add this code ?

I dont have a messagecontroller class, I only have BotController.cs should I add it there ?

Can I test this greeting in Bot Emulator or Should I try it in webchat itself ?

My requirement is to greet the user in the Directline Webchat.

1

1 Answers

0
votes

Yes using the ConversationUpdate Activity Type will achieve what you need, you will be able to greet the user as soon as they join the conversation in the Emulator and the same should work fine for WebChat.

If you are using the 11.qnamaker sample then yes, you can handle those type of activities inside QnABot.cs