c# - Azure 机器人框架| 如果一段时间没有用户回复,那么如何给用户发送提醒呢?
问题描述
通过上述问题,我的意思是-
如果机器人 10 秒内没有任何活动
机器人发送消息>>看起来你现在不在。
Bot>> 等你回来后再次 Ping 我。暂时再见。
解决方案
在 nodejs 中,您可以通过在轮流处理程序(onTurn 或 onMessage)中设置超时来执行此操作。如果您希望消息在用户的最后一条消息之后 X 次,则需要清除超时并在每轮重置它。超时将发送一次消息。如果您希望它重复,例如在用户的最后一条消息之后每X 次,您可以使用间隔而不是超时。我发现发送消息的最简单方法是作为主动消息,因此您确实需要使用此方法包含TurnContext
并BotFrameworkAdapter
从 botbuilder 库中获取。C# 的语法可能不同,但这应该为您指明正确的方向。这是我使用的功能:
async onTurn(context) {
if (context.activity.type === ActivityTypes.Message) {
// Save the conversationReference
const conversationData = await this.dialogState.get(context, {});
conversationData.conversationReference = TurnContext.getConversationReference(context.activity);
await this.conversationState.saveChanges(context);
console.log(conversationData.conversationReference);
// Reset the inactivity timer
clearTimeout(this.inactivityTimer);
this.inactivityTimer = setTimeout(async function(conversationReference) {
console.log('User is inactive');
try {
const adapter = new BotFrameworkAdapter({
appId: process.env.microsoftAppID,
appPassword: process.env.microsoftAppPassword
});
await adapter.continueConversation(conversationReference, async turnContext => {
await turnContext.sendActivity('Are you still there?');
});
} catch (error) {
//console.log('Bad Request. Please ensure your message contains the conversation reference and message text.');
console.log(error);
}
}, 300000, conversationData.conversationReference);
//<<THE REST OF YOUR TURN HANDLER>>
}
}
推荐阅读
- python - 正则表达式不会分隔最后一个字符串
- sql - How to change NULL label for checkbox to custom text in SSRS
- mysql - 如何在 SQL Case 函数中转换日期格式
- git - 在解决方案和源代码控制之间共享项目
- nhibernate - How can I intercept/prevent a property from being modified with (fluent) NHibernate?
- flowlang - 如何让流类型检查器检测我的文件中的更改?
- jsf - 提供基本的http认证
- css - 背景附件固定和容器宽度
- r - R 数据帧 + 逻辑运算
- go - 在 Go 中读取一个不断增长的 mmap 文件