欢迎消息在网络聊天中不可见,但在模拟器中有效
Welcome message not visibile in Webchat,but work in Emulator
IConversationUpdateActivity update = message;
using (var scope = Microsoft.Bot.Builder.Dialogs.Internals.DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var client = scope.Resolve<IConnectorClient>();
if (update.MembersAdded.Any())
{
foreach (var newMember in update.MembersAdded)
{
if (newMember.Id != message.Recipient.Id)
{
var reply = message.CreateReply();
reply.Text = $"Welcome {newMember.Name}!";
client.Conversations.ReplyToActivityAsync(reply);
}
}
}
}
我是使用 Microsoft BotFramework 进行 ChatBot 开发的新手。
我已经注册并部署了一个简单的机器人,它在模拟器上运行良好(即机器人说欢迎使用我的简单机器人),但是当我使用 WebChat 时没有显示欢迎问候语,而是当用户键入 Hi 或之后的任何文本时显示问候信息。
已经去了各种教程和解决方案,但没有得到确切的原因。我正在使用 Microsoft.Bot.Builder v3.12
我刚刚测试了您的代码并得到了相同的行为。奇怪的是,当机器人加入时似乎只有一个对话更新,而不是一个为机器人,一个为用户。我正在调查这个。如果你想试一试,下面的代码是有效的:
IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
if (iConversationUpdated != null)
{
ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
{
// if the bot is added, then
if (member.Id == iConversationUpdated.Recipient.Id)
{
var reply = ((Activity)iConversationUpdated).CreateReply(
$"Hi! I'm Botty McBotface and this is a welcome message");
connector.Conversations.ReplyToActivityAsync(reply);
}
}
}
IConversationUpdateActivity update = message;
using (var scope = Microsoft.Bot.Builder.Dialogs.Internals.DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var client = scope.Resolve<IConnectorClient>();
if (update.MembersAdded.Any())
{
foreach (var newMember in update.MembersAdded)
{
if (newMember.Id != message.Recipient.Id)
{
var reply = message.CreateReply();
reply.Text = $"Welcome {newMember.Name}!";
client.Conversations.ReplyToActivityAsync(reply);
}
}
}
}
我是使用 Microsoft BotFramework 进行 ChatBot 开发的新手。
我已经注册并部署了一个简单的机器人,它在模拟器上运行良好(即机器人说欢迎使用我的简单机器人),但是当我使用 WebChat 时没有显示欢迎问候语,而是当用户键入 Hi 或之后的任何文本时显示问候信息。 已经去了各种教程和解决方案,但没有得到确切的原因。我正在使用 Microsoft.Bot.Builder v3.12
我刚刚测试了您的代码并得到了相同的行为。奇怪的是,当机器人加入时似乎只有一个对话更新,而不是一个为机器人,一个为用户。我正在调查这个。如果你想试一试,下面的代码是有效的:
IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
if (iConversationUpdated != null)
{
ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
{
// if the bot is added, then
if (member.Id == iConversationUpdated.Recipient.Id)
{
var reply = ((Activity)iConversationUpdated).CreateReply(
$"Hi! I'm Botty McBotface and this is a welcome message");
connector.Conversations.ReplyToActivityAsync(reply);
}
}
}