2

By above question, I mean this-

If there is no activity on the bot for 10 seconds

Bot sends the message>> Looks like you aren't there for now.

Bot>> Ping me again once you are back. Bye for now.

  • 1
    If you search for "bot framework user idle" you will find tons of answers. – Hessel May 30 '20 at 12:49
  • Refer to https://stackoverflow.com/questions/56894802/how-to-detect-bot-idleness-on-bot-framework & https://stackoverflow.com/questions/54939184/set-timer-using-microsoft-bot-framework/54952783 and you can also send a [proactive message](https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=csharp) to your user. – ranusharao Jun 01 '20 at 22:08
  • Thanks @ranusharao.. I found the solution over https://stackoverflow.com/questions/56894802/how-to-detect-bot-idleness-on-bot-framework.. – Shwetanjali Dubey Jun 08 '20 at 04:17

1 Answers1

0

In nodejs you can do this by setting a timeout in your turn handler (onTurn or onMessage). You need to clear the timeout and reset it on every turn if you want the message to be X time after the user's last message. A timeout will send the message once. If you want it to repeat, e.g. every X time after the user's last message, you can use an interval instead of a timeout. I found the easiest way to send the message was as a proactive message, so you do need to include TurnContext and BotFrameworkAdapter from the botbuilder library with this method. The syntax is likely different for C#, but this should point you in the right direction. Here is the function I use:

    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>>
        }
    }
billoverton
  • 2,705
  • 2
  • 9
  • 32