How to use the botbuilder.ActivityTypes.ConversationUpdate function in botbuilder

To help you get started, we’ve selected a few botbuilder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / bot.js View on Github external
// Set the state with gathered properties (intent/ entities) through the onTurnAccessor.
            await this.onTurnAccessor.set(turnContext, onTurnProperties);

            // Create dialog context.
            const dc = await this.dialogs.createContext(turnContext);

            // Continue outstanding dialogs.
            await dc.continueDialog();

            // Begin main dialog if no outstanding dialogs/ no one responded.
            if (!dc.context.responded) {
                await dc.beginDialog(MainDispatcher.Name);
            }
            break;
        case ActivityTypes.ConversationUpdate:
            // Welcome user.
            await this.welcomeUser(turnContext);
            break;
        default:
            // Handle other activity types as needed.
            break;
        }

        // Persist state.
        // Hint: You can get around explicitly persisting state by using the autoStateSave middleware.
        await this.conversationState.saveChanges(turnContext);
        await this.userState.saveChanges(turnContext);
    }
    /**
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 12.nlp-with-luis / src / bot.ts View on Github external
if (topIntent.intent !== 'None') {
                await turnContext.sendActivity(`LUIS Top Scoring Intent: ${ topIntent.intent }, Score: ${ topIntent.score }`);
            } else {
                // If the top scoring intent was "None" tell the user no valid intents were found and provide help.
                await turnContext.sendActivity(`No LUIS intents were found.
                                                \nThis sample is about identifying two user intents:
                                                \n - 'Calendar.Add'
                                                \n - 'Calendar.Find'
                                                \nTry typing 'Add event' or 'Show me tomorrow'.`);
            }
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
            turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
            // If the Activity is a ConversationUpdate, send a greeting message to the user.
            await turnContext.sendActivity('Welcome to the NLP with LUIS sample! Send me a message and I will try to predict your intent.');
        } else if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
            // Respond to all other Activity types.
            await turnContext.sendActivity(`[${ turnContext.activity.type }]-type activity detected.`);
        }
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 14.nlp-with-dispatch / bot.js View on Github external
await this.weatherDialog.onTurn(turnContext);
                break;
            case QNA_INTENT:
                await this.qnaDialog.onTurn(turnContext);
                break;
            case NONE_INTENT:
            default:
                // Unknown request
                await turnContext.sendActivity(`I do not understand that.`);
                await turnContext.sendActivity(`I can help with weather forecast, turning devices on and off and answer general questions like 'hi', 'who are you' etc.`);
            }

            // save state changes
            await this.conversationState.saveChanges(turnContext);
            await this.userState.saveChanges(turnContext);
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
            // Handle ConversationUpdate activity type, which is used to indicates new members add to
            // the conversation.
            // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types

            // Do we have any new members added to the conversation?
            if (turnContext.activity.membersAdded.length !== 0) {
                // Iterate over all new members added to the conversation
                for (var idx in turnContext.activity.membersAdded) {
                    // Greet anyone that was not the target (recipient) of this message
                    // the 'bot' is the recipient for events from the channel,
                    // turnContext.activity.membersAdded == turnContext.activity.recipient.Id indicates the
                    // bot was added to the conversation.
                    if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id) {
                        // Welcome user.
                        // When activity type is "conversationUpdate" and the member joining the conversation is the bot
                        // we will send our Welcome Adaptive Card.  This will only be sent once, when the Bot joins conversation
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 20.qna-with-appinsights / bot.js View on Github external
async onTurn(turnContext) {
        // By checking the incoming activity's type, the bot only calls QnA Maker in appropriate cases.
        if (turnContext.activity.type === ActivityTypes.Message) {
            // Perform a call to the QnA Maker service to retrieve any potentially matching Question and Answer pairs.
            const qnaResults = await this.qnaMaker.generateAnswer(turnContext);

            if (qnaResults[0]) {
                // If an answer was received from QnA Maker, send the answer back to the user.
                await turnContext.sendActivity(qnaResults[0].answer);
            } else {
                // If no answers were returned from QnA Maker, reply to the user with examples of valid questions.
                await turnContext.sendActivity('No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. To see QnA Maker in action, ask the bot questions like "Why won\'t it turn on?" or say something like "I need help."');
            }
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
            turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
            // If the Activity is a ConversationUpdate, send a greeting message to the user.
            await turnContext.sendActivity(`Welcome to the QnA Maker sample! Ask me a question and I will try to answer it.`);
        } else if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
            // Respond to all other Activity types.
            await turnContext.sendActivity(`[${ turnContext.activity.type }]-type activity detected.`);
        }
    }
}
github microsoft / BotBuilder-Samples / experimental / multilingual-luis / javascript_typescript / src / bot.ts View on Github external
async onTurn(turnContext) {
        // By checking the incoming Activity type, the bot only calls LUIS in appropriate cases.
        if (turnContext.activity.type === ActivityTypes.Message) {
            // Perform a call to LUIS to retrieve results for the user's message.
            const results = await this.luisRecognizer.recognize(turnContext);
            await turnContext.sendActivity(`Your input message after translation is ${results.text}`);
            
            // Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
            const topIntent = results.luisResult.topScoringIntent;
            await turnContext.sendActivity(`After using LUIS recognition:\nthe top intent was:  ${ topIntent.intent }, Score: ${ topIntent.score }`);
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
            turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
            // If the Activity is a ConversationUpdate, send a greeting message to the user.
            await turnContext.sendActivity('"Hello and welcome to the Luis Sample bot."');
        }
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 05.multi-turn-prompt / bot.js View on Github external
}
            }

            // If the bot has not yet responded, continue processing the current dialog.
            await dc.continueDialog();

            // Start the sample dialog in response to any other input.
            if (!turnContext.responded) {
                const user = await this.userProfile.get(dc.context, {});
                if (user.name) {
                    await dc.beginDialog(HELLO_USER);
                } else {
                    await dc.beginDialog(WHO_ARE_YOU);
                }
            }
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
            // Do we have any new members added to the conversation?
            if (turnContext.activity.membersAdded.length !== 0) {
                // Iterate over all new members added to the conversation
                for (var idx in turnContext.activity.membersAdded) {
                    // Greet anyone that was not the target (recipient) of this message.
                    // Since the bot is the recipient for events from the channel,
                    // context.activity.membersAdded === context.activity.recipient.Id indicates the
                    // bot was added to the conversation, and the opposite indicates this is a user.
                    if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id) {
                        // Send a "this is what the bot does" message.
                        const description = [
                            'I am a bot that demonstrates the TextPrompt and NumberPrompt classes',
                            'to collect your name and age, then store those values in UserState for later use.',
                            'Say anything to continue.'
                        ];
                        await turnContext.sendActivity(description.join(' '));
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 12.nlp-with-luis / src / bot.ts View on Github external
const results: RecognizerResult = await this.luisRecognizer.recognize(turnContext);

            // Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
            const topIntent = results.luisResult.topScoringIntent;

            if (topIntent.intent !== 'None') {
                await turnContext.sendActivity(`LUIS Top Scoring Intent: ${ topIntent.intent }, Score: ${ topIntent.score }`);
            } else {
                // If the top scoring intent was "None" tell the user no valid intents were found and provide help.
                await turnContext.sendActivity(`No LUIS intents were found.
                                                \nThis sample is about identifying two user intents:
                                                \n - 'Calendar.Add'
                                                \n - 'Calendar.Find'
                                                \nTry typing 'Add event' or 'Show me tomorrow'.`);
            }
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate &&
            turnContext.activity.recipient.id !== turnContext.activity.membersAdded[0].id) {
            // If the Activity is a ConversationUpdate, send a greeting message to the user.
            await turnContext.sendActivity('Welcome to the NLP with LUIS sample! Send me a message and I will try to predict your intent.');
        } else if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
            // Respond to all other Activity types.
            await turnContext.sendActivity(`[${ turnContext.activity.type }]-type activity detected.`);
        }
    }
}
github microsoft / botbuilder-js / libraries / botbuilder-ai / samples / 13.basic-bot / bot.js View on Github external
break;
                    }
                    break;
                case DialogTurnStatus.waiting:
                    // The active dialog is waiting for a response from the user, so do nothing.
                    break;
                case DialogTurnStatus.complete:
                    // All child dialogs have ended. so do nothing.
                    break;
                default:
                    // Unrecognized status from child dialog. Cancel all dialogs.
                    await dc.cancelAllDialogs();
                    break;
                }
            }
        } else if (context.activity.type === ActivityTypes.ConversationUpdate) {
            // Handle ConversationUpdate activity type, which is used to indicates new members add to
            // the conversation.
            // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types

            // Do we have any new members added to the conversation?
            if (context.activity.membersAdded.length !== 0) {
                // Iterate over all new members added to the conversation
                for (var idx in context.activity.membersAdded) {
                    // Greet anyone that was not the target (recipient) of this message
                    // the 'bot' is the recipient for events from the channel,
                    // context.activity.membersAdded == context.activity.recipient.Id indicates the
                    // bot was added to the conversation.
                    if (context.activity.membersAdded[idx].id !== context.activity.recipient.id) {
                        // Welcome user.
                        // When activity type is "conversationUpdate" and the member joining the conversation is the bot
                        // we will send our Welcome Adaptive Card.  This will only be sent once, when the Bot joins conversation
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 81.skills-skilldialog / dialogRootBot / bots / rootBot.js View on Github external
this.onTurn(async (turnContext, next) => {
            if (turnContext.activity.type !== ActivityTypes.ConversationUpdate) {
                // Run the Dialog with the activity.
                await runDialog(this.dialog, turnContext, this.conversationState.createProperty('DialogState'));
            }

            await next();
        });
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 18.bot-authentication / bot.js View on Github external
if (text === 'help') {
                    await turnContext.sendActivity(HELP_TEXT);
                }
                // Log the user out
                if (text === 'logout') {
                    let botAdapter = turnContext.adapter;
                    await botAdapter.signOutUser(turnContext, CONNECTION_NAME);
                    await turnContext.sendActivity('You have been signed out.');
                    await turnContext.sendActivity(HELP_TEXT);
                }
            } else {
                if (!turnContext.responded) {
                    await dc.beginDialog(AUTH_DIALOG);
                }
            };
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
            // Send a greeting to new members that join the conversation.
            const members = turnContext.activity.membersAdded;

            for (let index = 0; index < members.length; index++) {
                const member = members[index];
                if (member.id !== turnContext.activity.recipient.id) {
                    const welcomeMessage = `Welcome to AuthenticationBot ${ member.name }. ` + HELP_TEXT;
                    await turnContext.sendActivity(welcomeMessage);
                }
            };
        } else if (turnContext.activity.type === ActivityTypes.Invoke || turnContext.activity.type === ActivityTypes.Event) {
            // This handles the MS Teams Invoke Activity sent when magic code is not used.
            // See: https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/authentication/auth-oauth-card#getting-started-with-oauthcard-in-teams
            // The Teams manifest schema is found here: https://docs.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema
            // It also handles the Event Activity sent from the emulator when the magic code is not used.
            // See: https://blog.botframework.com/2018/08/28/testing-authentication-to-your-bot-using-the-bot-framework-emulator/