如何使用 Microsoft Bot Framework 显示来自我的 Bot 的欢迎消息
How to display a welcome message from my Bot using Microsoft Bot Framework
我想在有人连接到我的机器人时显示欢迎消息。我在 github (https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers) 上使用了 demo-ContosoFlowers 示例中的技术,它在 Bot Framework Emulator 中运行良好,但在 Skype 或 Facebook Messenger 中运行良好。具体来说,MessageController.HandleSystemMessage 中的这段代码不会触发:
else if (message.Type == ActivityTypes.ConversationUpdate)
{
if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
{
var reply = message.CreateReply(Resources.RootDialog_Welcome_Message);
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
有谁知道如何正确执行此操作?
我今天还试用了 ContosoFlowers 演示。我遇到了您描述的相同行为:在模拟器中,ConversationUpdate 代码被触发,但在 Skype 中却没有。但是,我确实注意到 ContactRelationUpdate activity 类型确实在 Skype 中触发(我没有尝试过 Facebook Messenger)。如果您的目标是在有人 "connects" 访问您的机器人时显示欢迎消息,您可以尝试使用 ContactRelationUpdate activity 类型,如下所示:
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
if(message.Action == "add")
{
var reply = message.CreateReply("WELCOME!!!");
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
创建一个 class 并将其放入 fb 的回调 url 中。 FacebookProfile 是我的 class,它保存着通话后的姓名和其他信息。
public static async Task<FacebookProfile> GetFacebookProfile(string accessToken)
{
var uri = GetUri("https://graph.facebook.com/v2.6/me",
Tuple.Create("fields", "name,email,id,first_name,last_name"),
Tuple.Create("access_token", accessToken));
var res = await FacebookRequest<FacebookProfile>(uri);
return res;
}
我想在有人连接到我的机器人时显示欢迎消息。我在 github (https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/demo-ContosoFlowers) 上使用了 demo-ContosoFlowers 示例中的技术,它在 Bot Framework Emulator 中运行良好,但在 Skype 或 Facebook Messenger 中运行良好。具体来说,MessageController.HandleSystemMessage 中的这段代码不会触发:
else if (message.Type == ActivityTypes.ConversationUpdate)
{
if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
{
var reply = message.CreateReply(Resources.RootDialog_Welcome_Message);
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
有谁知道如何正确执行此操作?
我今天还试用了 ContosoFlowers 演示。我遇到了您描述的相同行为:在模拟器中,ConversationUpdate 代码被触发,但在 Skype 中却没有。但是,我确实注意到 ContactRelationUpdate activity 类型确实在 Skype 中触发(我没有尝试过 Facebook Messenger)。如果您的目标是在有人 "connects" 访问您的机器人时显示欢迎消息,您可以尝试使用 ContactRelationUpdate activity 类型,如下所示:
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
if(message.Action == "add")
{
var reply = message.CreateReply("WELCOME!!!");
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
创建一个 class 并将其放入 fb 的回调 url 中。 FacebookProfile 是我的 class,它保存着通话后的姓名和其他信息。
public static async Task<FacebookProfile> GetFacebookProfile(string accessToken)
{
var uri = GetUri("https://graph.facebook.com/v2.6/me",
Tuple.Create("fields", "name,email,id,first_name,last_name"),
Tuple.Create("access_token", accessToken));
var res = await FacebookRequest<FacebookProfile>(uri);
return res;
}