如何使用Microsoft bot框架SDK3 C#在Microsoft团队中显示欢迎消息

时间:2018-08-31 06:04:33

标签: botframework

根据this,去年在使用ActivityTypes.ConversationUpdate时似乎无法在Microsoft团队中显示欢迎消息。

我想知道现在是否有可能。有什么建议吗?

我已经尝试过了,但是似乎没有用。

  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)
            {
                // 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
             if (message.Conversation.IsGroup == true)
                {
                bool addedBot = false;
                Activity newMessage = new Activity();
                string res = "";
                for (int i = 0; i < message.MembersAdded.Count; i++)
                {
                    if (message.MembersAdded[i].Id == message.Recipient.Id)
                    {
                        addedBot = true;
                        break;
                    }
                }

                if (message.MembersAdded.Count > 0 && addedBot == false)
                {

                    ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
                    Activity reply = message.CreateReply("test");
                    connector.Conversations.ReplyToActivityAsync(reply);

                }
              }
              else
              {
                    ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
                    Activity reply = message.CreateReply("test");
                    connector.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
            }
            //else if (message.Type == ActivityTypes.Ping)
            //{
            //}

            return null;
        }

2018/09/06

有效。

1 个答案:

答案 0 :(得分:0)

我的代码有效。但是添加bot时似乎无法发送其他现有用户 1对1消息。