首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure Bot Framework|如果用户有一段时间没有响应,那么如何向用户发送提醒?

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

Stack Overflow用户
提问于 2020-05-30 19:49:13
回答 1查看 207关注 0票数 2

通过上面的问题,我的意思是-

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

机器人发送的message>>看起来你现在不在那里。

一旦你回来了,Bot>>再给我发一次Ping。再见了。

EN

回答 1

Stack Overflow用户

发布于 2020-06-02 02:19:03

在nodejs中,您可以通过在轮到处理程序(onTurn或onMessage)中设置超时来完成此操作。如果您希望消息在用户的最后一条消息之后X次,则需要清除超时并在每次转弯时将其重置。超时将发送一次消息。如果您希望它重复,例如,在用户的最后一条消息之后每次超时X次,您可以使用间隔而不是超时。我发现发送消息的最简单方法是作为主动消息,因此您确实需要在此方法中包含来自botbuilder库的TurnContextBotFrameworkAdapter。C#的语法可能有所不同,但这应该会为您指明正确的方向。下面是我使用的函数:

代码语言:javascript
复制
    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>>
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62101972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档