所以为了解释我的问题,我必须给你背景。
我得到了一个使用 slack 上部署的 microsoft bot 框架构建的 Bot。现在它可以在机器人与之通信的我的后端发生这些“事件”。当一个事件发生时,我想通知我的机器人,然后让它向所有的对话发送一条消息,告诉它发生了什么事。所以基本上:
Backend>Microserivce>Bot>users
为此,我必须将所有对话存储在我的后端,我在那里的数据库中进行。当事件发生时,后端将向机器人发布一个活动,其中包含所有对话(基本上是他们的 id)以及它应该显示的事件。
所以本质上我的后端需要向我的机器人发布消息。
为此,我在这里找到了充当中间人的 microsoft directline api,这是一种与机器人交谈的更抽象的方式。问题是我不知道该怎么做。我遵循了微软自己的教程,但它似乎对我不起作用:
这是我的后端用来通知机器人的端点。“内容”包含作为 json 格式字符串的对话和事件。
[HttpPost]
[Route("conversationsEvents")]
public HttpResponseMessage PostConversationsEvents([FromBody]string content)
{
NotifyBot.Notify(content);
return Request.CreateResponse(HttpStatusCode.NoContent );
}
NotifyBot.Notify(content) 看起来像这样:
private static async Task StartBotConversation( string contents)
{
string directLineSecret = "secret";
string fromUser = "microserviceNotifyEndpoint";
Activity activity = new Activity
{
From = new ChannelAccount(fromUser),
Text = contents,
Type = ActivityTypes.Event
};
DirectLineClient client = new DirectLineClient(directLineSecret);
var conversation = await client.Conversations.StartConversationAsync();
await client.Conversations.PostActivityAsync(conversation.ConversationId, activity);
}
基本上执行被卡在var conversation = await client.Conversations.StartConversationAsync();
,它只是永远等待。我尝试将其更改为var conversation = await client.Conversations.StartConversationAsync().ConfigureAwait(continueOnCapturedContext: false);
“执行继续,但活动似乎没有发布。