我可以使用机器人构建器示例中描述的方式向对话发送主动消息。到目前为止我发现的所有样本都依赖于ConversationReference内存中保存的。
我还能够从成绩单 blob 存储中获取一条消息并回复该消息。
但我真正想要实现的是ConversationReference通过手动实例化它来创建有效的。但我无法弄清楚必须设置才能使其工作所需的属性。我知道channelId、serviceUrl 和conversationId。
有人有一个如何生成有效的示例吗ConversationReference?
我相信有些渠道可能会有不同的要求。如果您正在寻找如何在特定频道上执行此操作,我可以更新此答案。对于 DirecLine/Webchat,我编辑了示例 16.proactive-messages。在 中NotifyController.cs,我将Get()方法更改为:
public async Task<IActionResult> Get()
{
foreach (var conversationReference in _conversationReferences.Values)
{
// Here, I create my own ConversationReference from a known one for the purpose of testing requirements
// I found that this is the bare minimum for WebChat/DirectLine
var newReference = new ConversationReference()
{
Bot = new ChannelAccount()
{
Id = conversationReference.Bot.Id
},
Conversation = new ConversationAccount()
{
Id = conversationReference.Conversation.Id
},
ServiceUrl = conversationReference.ServiceUrl,
};
// You may need this to ensure the message isn't rejected
MicrosoftAppCredentials.TrustServiceUrl(conversationReference.ServiceUrl);
// Here, I replaced conversationReference with newReference, to ensure it's using the one I created
await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, newReference, BotCallback, default(CancellationToken));
}
// Let the caller know proactive messages have been sent
return new ContentResult()
{
Content = "<html><body><h1>Proactive messages have been sent.</h1></body></html>",
ContentType = "text/html",
StatusCode = (int)HttpStatusCode.OK,
};
}
Run Code Online (Sandbox Code Playgroud)
因此,正如您所看到的,最小值似乎是:
var newReference = new ConversationReference()
{
Bot = new ChannelAccount()
{
Id = conversationReference.Bot.Id
},
Conversation = new ConversationAccount()
{
Id = conversationReference.Conversation.Id
},
ServiceUrl = conversationReference.ServiceUrl,
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1170 次 |
| 最近记录: |