【发布时间】:2017-07-12 21:46:30
【问题描述】:
我希望我的机器人在用户开始新对话时显示介绍性消息。我在 Skype 中看到了这种与机器人一起工作的情况,其中机器人在用户输入任何内容之前发送消息。
我已经使用 Bot Framework Channel Emulator 和 MessagesController 类中的此代码来完成这项工作:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
await this.HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private async Task HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.ConversationUpdate)
{
var reply = message.CreateReply("Hello World!");
var connector = new ConnectorClient(new Uri(message.ServiceUrl));
await connector.Conversations.SendToConversationAsync(reply);
}
}
这将显示“Hello World!”在新对话开始时。无需输入。但是,在 Skype 上,不会出现此介绍性消息。我在这里误解了什么?我知道这是可能的。
【问题讨论】:
-
谢谢你,这很有趣。下面接受的答案正好回答了我的问题
标签: c# botframework