通过上面的问题,我的意思是-
如果机器人在10秒内没有任何活动
机器人发送的message>>看起来你现在不在那里。
一旦你回来了,Bot>>再给我发一次Ping。再见了。
发布于 2020-06-02 02:19:03
在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>>
}
}https://stackoverflow.com/questions/62101972
复制相似问题