show welcome message in Microsoft teams using Microsoft bot framework

旧巷老猫 提交于 2019-12-03 13:56:30

问题


I have used below code for showing a welcome message to user.

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.ConversationUpdate)
            {
                string replyMessage = string.Empty;
                replyMessage = Responses.Greeting;
                return message.CreateReply(replyMessage);
            }
            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
            }
            else if (message.Type == ActivityTypes.Ping)
            {
            }
            return null;
        }

Below method is used to call HandleSystemMessage, if activity type is not message.

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            string reply = "";
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            if (activity.Type == ActivityTypes.Message)
            {
                    stLuis = await LuisHelper.ParseUserInput(activity.Text);

                    string userResponse = activity.Text.ToLower();

                    switch (stLuis.topScoringIntent.intent)
                    {
                        case "Greetings":
                            reply = Responses.Greeting;
                            break; 

                        case "None":
                            reply = Responses.None;
                            break;

                        default:
                            break;
                    }
                }

                if (reply != "")
                    await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(reply));
            }
            else
            {
                var reply1 = HandleSystemMessage(activity);
                if (reply1 != null)
                    await connector.Conversations.ReplyToActivityAsync(reply1);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK); 
            return response;
        }

This code works with Skype. But when I add same bot in Microsoft teams, it doesn't show a welcome message.


回答1:


By now (2016-12-30) MSFT Teams does not send any message at all when you add a bot to "contact list". This is a known limitation and to be addressed in the nearest future, as MSFT guys say.

In the meantime to get a ConversationUpdate message to the bot, the user will have to first initiate a conversation with the bot.

As a workaround you can handle special text sent from user, like "start", or just the very first incoming message, if your bot is stateful enough.



来源:https://stackoverflow.com/questions/40839436/show-welcome-message-in-microsoft-teams-using-microsoft-bot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!