简体   繁体   中英

When user sends message to my bot, he receives Welcome message. But when user respond to that, bot sends Welcome message again. How can I fix this?

I am developing a chatbot using Microsoft Bot Framework and i recently upgraded the framework 3.0 to 3.5. before upgrading it was working fine but now

When user sends message to my bot, he receives Welcome message. But when user respond to that, bot sends Welcome message again. How can I fix this? here s the code.

private Activity 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.ContactRelationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels               
            }
            else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels
                logger.Debug("Activity Type " + message.Type);
                logger.Debug("Inside conversation update and activity Id is :-"+ message.Id);
                ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
                Activity reply = message.CreateReply(ConstantsTable.WelcomeMessage);                                
                connector.Conversations.ReplyToActivityAsync(reply);
                message.Type = ActivityTypes.Message;                    
            }
            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
                ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
                Activity reply = message.CreateReply("You are typing");
                connector.Conversations.ReplyToActivityAsync(reply);
            }
            else if (message.Type == ActivityTypes.Ping)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
                Activity reply = message.CreateReply("Hello PING. Please reply");
                connector.Conversations.ReplyToActivityAsync(reply);
            }

            return message;
        }

But in local emulator it's work fine while publishing only this is happening. Please help.

I believe this could be related to a change that was rolled out a few days ago; where Direct Line will send more ConversationUpdate messages than it used to.

Check the announcement and a related issue (similar to yours, but in node.js ).

The first ConversationUpdate is sent when the bot is added to the conversation. After that, each additional ConversationUpdate is sent when a new user joins the conversation.

So, I think the solution here will be to check the members added ( activity.MembersAdded )

    else if (message.Type == ActivityTypes.ConversationUpdate)
    {
        if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
        {
            // logic
        }
    }

You need to handle that within the main dialog using switch operations based on intent and also adding dialogs for the relevant intent.

There is a difference between introduction and greeting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM