以上问题,我的意思是-
[如果机器人在10秒钟内没有任何活动
Bot发送消息>>看来您暂时不在。
Bot >>回来后再次向我发送邮件。暂时再见。
在nodejs中,您可以通过在转弯处理程序(onTurn或onMessage)中设置超时来实现。如果您希望该消息在用户的最后一条消息之后是X时间,则需要清除超时并在每次转弯时将其重置。超时将发送一次消息。如果您想重复,例如每一个用户的最后一条消息之后的X次,您可以使用间隔而不是超时。我发现发送消息的最简单方法是作为主动消息,因此您确实需要使用此方法包括botbuilder库中的TurnContext
和BotFrameworkAdapter
。 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>>
}
}