botframework - 向用户发送主动消息的技能机器人
问题描述
- 我开发了一个向用户发送主动消息的机器人
- 我还创建了触发技能的机器人。我试图写一些东西,技能机器人/对话能够将通过 webhook 收到的主动消息发送给用户并继续现有的技能对话。我不能完全理解。如果有人可以在那里帮助我。
我使用此处的示例创建了一个简单的技能机器人,它保存ConversationReference
当前活动并调用服务OnMessageActivityReceived()
// Save ConversationReference
var conversationReference = activity.GetConversationReference();
_conversationReferences.AddOrUpdate(conversationReference.User.Id, conversationReference, (key, newValue) => conversationReference);
// Calling external service
HttpResponseMessage responsemMsg = await client.PostAsync(RequestURI, stringContent);
if (responsemMsg.IsSuccessStatusCode)
{
var apiResponse = await responsemMsg.Content.ReadAsStringAsync();
//Post the API response to bot again
await turnContext.SendActivityAsync(MessageFactory.Text($"Message Sent {turnContext.Activity.Text}"), cancellationToken);
}
被调用的服务最终会发出一个事件,该事件调用NotifyController
我的技能机器人中的一个动作。它尝试使用 获取ConverstaionReference
并发送活动TurnContext
。
//I am using the Skill Bot Id for _appId parameter
await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, async (context, token) =>
{
await context.SendActivityAsync(proMsg.eventName);
await context.SendActivityAsync(proMsg.context.ToString());
}, new System.Threading.CancellationToken());
此 SendActivity 失败,来自 Skill Bot 的 OnTurnError 处理异常。我不确定我哪里出错了。我是 Bot 框架学习的新手。
解决方案
我的问题通过使用带有 ClaimsIdentity 的 ContinueConversation() 重载并为受众、appid 等设置正确的声明得到解决。这基本上是身份验证问题。
public virtual Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, ConversationReference reference, string audience, BotCallbackHandler callback, CancellationToken cancellationToken);
推荐阅读
- subtitle - 如何删除 [ ] 之间的文本?
- android - android studio中的Firebase列表适配器
- python - 可视化 Apriori 算法
- c# - 如何在excel底部添加额外的信息栏?
- java - 根据条件拆分对象集合
- c# - 在 Windows 10 上将 .NET Core 控制台应用程序切换到全屏模式
- amazon-web-services - EC2 实例连接:设置实例连接时出现问题
- javascript - 为什么在 Javascript 中使用 async 而不使用 await?
- sql - 使用 LEFT JOIN 和 ON 语句仅选择最接近的值
- c# - 如何使统一的 Random.Range() 更加随机?