How to use the botbuilder.ActivityTypes.Message 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 / 16.proactive-messages / bot.js View on Github external
async onTurn(turnContext) {
        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        if (turnContext.activity.type === ActivityTypes.Message) {
            const utterance = (turnContext.activity.text || '').trim().toLowerCase();
            var jobIdNumber;

            // If user types in run, create a new job.
            if (utterance === 'run') {
                await this.createJob(turnContext);
            } else if (utterance === 'show') {
                await this.showJobs(turnContext);
            } else {
                const words = utterance.split(' ');

                // If the user types done and a Job Id Number,
                // we check if the second word input is a number.
                if (words[0] === 'done' && !isNaN(parseInt(words[1]))) {
                    jobIdNumber = words[1];
                    await this.completeJob(turnContext, jobIdNumber);
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 12.nlp-with-luis / src / bot.ts View on Github external
public async onTurn(turnContext: 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: 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'.`);
            }
github howdyai / botkit / packages / botbuilder-dialogs-botkit-cms / src / index.ts View on Github external
async continueDialog(dc) {

        // Don't do anything for non-message activities
        if (dc.context.activity.type !== ActivityTypes.Message) {
            return Dialog.EndOfTurn;
        }

        // Run next step with the message text as the result.
        return await this.resumeDialog(dc, DialogReason.continueCalled, dc.context.activity.text);
    }
github howdyai / botkit / packages / botbuilder-adapter-web / src / web_adapter.ts View on Github external
const activity = {
            timestamp: new Date(),
            channelId: 'webhook',
            conversation: {
                id: message.user
            },
            from: {
                id: message.user
            },
            recipient: {
                id: 'bot'
            },
            channelData: message,
            text: message.text,
            type: message.type === 'message' ? ActivityTypes.Message : ActivityTypes.Event
        };

        // set botkit's event type
        if (activity.type !== ActivityTypes.Message) {
            activity.channelData.botkitEventType = message.type;
        }

        // create a conversation reference
        const context = new TurnContext(this, activity as Activity);

        context.turnState.set('httpStatus', 200);

        await this.runMiddleware(context, logic);

        // send http response back
        res.status(context.turnState.get('httpStatus'));
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 23.facebook-events / bot.js View on Github external
async onTurn(turnContext) {
        // These are the 3 main Facebook features we show in this sample
        const facebookPageNameOption = 'Facebook Page Name';
        const quickRepliesOption = 'Quick Replies';
        const postBackOption = 'PostBack';

        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        if (turnContext.activity.type === ActivityTypes.Message) {
            const text = turnContext.activity.text;

            // Check if we are on the Facebook channel.
            if (turnContext.activity.channelId === 'facebook') {
                // Analyze Facebook payload from channel data.
                processFacebookPayload(turnContext.activity.channelData);

                // Initially the bot offers to showcase 3 Facebook features: Quick replies, PostBack and getting the Facebook Page Name.
                // Below we also show how to get the messaging_optin payload as well.
                switch (text) {
                // Here we showcase how to obtain the Facebook page name.
                // This can be useful for the Facebook multi-page support provided by the Bot Framework.
                // The Facebook page name from which the message comes from is in turnContext.activity.recipient.name.
                case facebookPageNameOption:
                    await turnContext.sendActivity(`This message comes from the following Facebook Page: ${ turnContext.activity.recipient.name }`);
                    break;
github microsoft / BotBuilder-Samples / javascript_nodejs / 08.suggested-Actions / bot.js View on Github external
async onTurn(turnContext) {
        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        if (turnContext.activity.type === ActivityTypes.Message) {
            const text = turnContext.activity.text;

            // Create an array with the valid color options.
            const validColors = ['Red', 'Blue', 'Yellow'];

            // If the `text` is in the Array, a valid color was selected and send agreement. 
            if (validColors.includes(text)) {
                await turnContext.sendActivity(`I agree, ${text} is the best color.`);
            } else {
                await turnContext.sendActivity('Please select a color.');
            }

            // After the bot has responded send the SuggestedActions.
            await sendSuggestedActions(turnContext);
        } else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
            let members = turnContext.activity.membersAdded;
github microsoft / BotBuilder-Samples / generators / generator-botbuilder / generators / app / templates / core / bot.js View on Github external
async onTurn(context) {
        // Handle Message activity type, which is the main activity type for shown within a conversational interface
        // Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
        if (context.activity.type === ActivityTypes.Message) {
            let dialogResult;
            // Create a dialog context
            const dc = await this.dialogs.createContext(context);

            // Perform a call to LUIS to retrieve results for the current activity message.
            const results = await this.luisRecognizer.recognize(context);
            const topIntent = LuisRecognizer.topIntent(results);

            // update user profile property with any entities captured by LUIS
            // This could be user responding with their name or city while we are in the middle of greeting dialog,
            // or user saying something like 'i'm {userName}' while we have no active multi-turn dialog.
            await this.updateUserProfile(results, context);

            // Based on LUIS topIntent, evaluate if we have an interruption.
            // Interruption here refers to user looking for help/ cancel existing dialog
            const interrupted = await this.isTurnInterrupted(dc, results);
github BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-middleware-watson-nlu / src / concepts.ts View on Github external
public async onTurn(context: TurnContext, next: () => Promise): Promise {
        if(context.activity.type === ActivityTypes.Message) {
            const input = {
                documents: [
                    {
                        'id': '1'
                        , 'text': context.activity.text
                    }
                ]
            };
            try {
                const result = await this.engine.concepts(input);
                const l = result.documents[0].concepts;
                context.turnState.set('conceptEntities', l);
            }
            catch(e) {
                throw new Error(`Failed to process concepts on ${ context.activity.text }. Error: ${ e }`);
            }
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 52.enterprise-bot / src / utils / activityEx.ts View on Github external
export function createReply(source: Activity, text?: string, local?: string): Activity {
        const reply = text || "";
        return {
            channelId: source.channelId,
            conversation: source.conversation,
            from: source.recipient,
            label: source.label,
            locale: local,
            recipient: source.from,
            replyToId: source.id,
            serviceUrl: source.serviceUrl,
            text: reply,
            timestamp: new Date(),
            type: ActivityTypes.Message,
            valueType: source.valueType,
        };
    }
}
github BotBuilderCommunity / botbuilder-community-js / libraries / botbuilder-middleware-aws-comprehend / src / keyPhrases.ts View on Github external
public async onTurn(context: TurnContext, next: () => Promise): Promise {
        if(context.activity.type === ActivityTypes.Message) {
            const input = {
                documents: [
                    {
                        'id': '1'
                        , 'text': context.activity.text
                    }
                ]
            };
            try {
                const result = await this.engine.keyPhrases(input);
                const k = result.documents[0].keyPhrases;
                context.turnState.set('keyPhrases', k);
            }
            catch(e) {
                throw new Error(`Failed to process key phrases on ${ context.activity.text }. Error: ${ e }`);
            }