Azure Bot Framework |如果一段时间以来用户没有任何响应,那么如何向用户发送提醒?

问题描述 投票:1回答:1

以上问题,我的意思是-

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

Bot发送消息>>看来您暂时不在。

Bot >>回来后再次向我发送邮件。暂时再见。

c# botframework azure-web-app-service
1个回答
0
投票

在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>>
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.