僵尸程序添加时,我只是想向用户发送欢迎消息。我已经编写了以下代码,但是我收到“ exceptionMessage”:“'ReplyToId'不能为null。”在bot JSON结果中。

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
                    IConversationUpdateActivity conversationupdate = message;
                    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
                    {
                        var client = scope.Resolve<IConnectorClient>();
                        if (conversationupdate.MembersAdded.Any())
                        {
                            var reply = message.CreateReply();
                            foreach (var newMember in conversationupdate.MembersAdded)
                            {
                                if (newMember.Id != message.Recipient.Id)
                                {
                                    reply.Text = $"Welcome {newMember.Name}! ";
                                }
                                else
                                {
                                    reply.Text = $"Welcome {message.From.Name}";

                                }
                                await client.Conversations.ReplyToActivityAsync(message);
                            }
                        }
                    }
                }

最佳答案

看来您未正确创建回复。您正在使用传入的消息,而不是从中创建答复。

这是有效的代码,您应该完全适应您的情况:

else if (message.Type == ActivityTypes.ConversationUpdate)
{
     if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
     {
             var reply = message.CreateReply("Welcome!");

             ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));

             await connector.Conversations.ReplyToActivityAsync(reply);
      }
}

关于c# - “exceptionMessage”:“'ReplyToId'不能为空。”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43540531/

10-13 03:12