【问题标题】:Azure Bot Framework| If there is no response from the user for some time, then how to send reminder to the users?Azure 机器人框架|如果一段时间没有用户回复,那么如何给用户发送提醒呢?
【发布时间】:2020-10-15 22:44:05
【问题描述】:

上面的问题,我的意思是这个-

如果机器人 10 秒内没有任何活动

Bot 发送消息>> 看起来你现在不在。

Bot>> 等你回来后再次 Ping 我。暂时再见。

【问题讨论】:

标签: c# botframework azure-web-app-service


【解决方案1】:

在 nodejs 中,您可以通过在轮流处理程序(onTurn 或 onMessage)中设置超时来做到这一点。如果您希望消息在用户的最后一条消息之后 X 次,您需要清除超时并在每一轮重置它。超时将发送一次消息。如果你想让它重复,例如在用户发送最后一条消息后 X 次,您可以使用间隔而不是超时。我发现发送消息的最简单方法是作为主动消息,因此您需要使用此方法从 botbuilder 库中包含 TurnContextBotFrameworkAdapter。 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>>
        }
    }

【讨论】:

  • 此解决方案对您有用吗?如果是这样,请考虑接受和投票,以便其他人可以找到答案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-04
  • 1970-01-01
  • 2017-12-20
  • 1970-01-01
  • 1970-01-01
  • 2017-06-23
  • 2022-10-13
相关资源
最近更新 更多