How to use the botbuilder-core.ActivityTypes.Message function in botbuilder-core

To help you get started, we’ve selected a few botbuilder-core 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 / typescript_nodejs / 01.console-echo / src / consoleAdapter.ts View on Github external
rl.on('line', (line: string) => {
            // Initialize activity
            const activity: Partial = TurnContext.applyConversationReference(
                {
                    id: (this.nextId++).toString(),
                    text: line,
                    timestamp: new Date(),
                    type: ActivityTypes.Message
                },
                this.reference,
                true
            );

            // Create context and run middleware pipe
            const context: TurnContext = new TurnContext(this, activity);
            this.runMiddleware(context, logic)
                .catch((err: Error) => { this.printError(err.toString()); });
        });
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / src / prompts / activityPrompt.ts View on Github external
// Validate the return value
        // - Unlike the other prompts a validator is required for an ActivityPrompt so we don't
        //   need to check for its existence before calling it.
        const isValid: boolean = await this.validator({
            context: dc.context,
            recognized: recognized,
            state: state.state,
            options: state.options,
            attemptCount: ++state.state['attemptCount']
        });

        // Return recognized value or re-prompt
        if (isValid) {
            return await dc.endDialog(recognized.value);
        } else {
            if (dc.context.activity.type === ActivityTypes.Message && !dc.context.responded) {
                await this.onPrompt(dc.context, state.state, state.options, true);
            }

            return Dialog.EndOfTurn;
        }
    }
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / adaptiveDialog.ts View on Github external
}

        // Perform default processing
        if (preBubble) {
            switch (event.name) {
                case AdaptiveEventNames.beginDialog:
                    const activityReceivedEvent: DialogEvent = {
                        name: AdaptiveEventNames.activityReceived,
                        value: sequence.context.activity,
                        bubble: false
                    }
                    handled = await this.processEvent(sequence, activityReceivedEvent, true);
                    break;
                case AdaptiveEventNames.activityReceived:
                    const activity = sequence.context.activity;
                    if (activity.type === ActivityTypes.Message) {
                        // Recognize utterance
                        const recognizeUtteranceEvent: DialogEvent = {
                            name: AdaptiveEventNames.recognizeUtterance,
                            value: sequence.context.activity,
                            bubble: false
                        };
                        await this.processEvent(sequence, recognizeUtteranceEvent, true);

                        const recognized = sequence.state.getValue('turn.recognized').value;
                        const recognizedIntentEvent: DialogEvent = {
                            name: AdaptiveEventNames.recognizedIntent,
                            value: recognized,
                            bubble: false
                        }
                        handled = await this.processEvent(sequence, recognizedIntentEvent, true);
                    }
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / adaptiveDialog.ts View on Github external
break;
            }
        } else {
            switch (event.name) {
                case AdaptiveEventNames.beginDialog:
                    const activityReceivedEvent: DialogEvent = {
                        name: AdaptiveEventNames.activityReceived,
                        value: sequence.context.activity,
                        bubble: false
                    };
                    // Emit trailing ActivityReceived event
                    handled = await this.processEvent(sequence, activityReceivedEvent, false);
                    break;
                case AdaptiveEventNames.activityReceived:
                    const activity = sequence.context.activity;
                    if (activity.type === ActivityTypes.Message) {
                        // Do we have an empty sequence?
                        if (sequence.actions.length == 0) {
                            const unknownIntentEvent: DialogEvent = {
                                name: AdaptiveEventNames.unknownIntent,
                                bubble: false
                            };
                            // Emit trailing UnknownIntent event
                            handled = await this.processEvent(sequence, unknownIntentEvent, false);
                        } else {
                            handled = false;
                        }
                    }

                    if (handled) {
                        sequence.state.setValue('turn.interrupted', true);
                    }
github microsoft / botbuilder-js / libraries / botbuilder-testing / src / dialogTestLogger.ts View on Github external
activities.forEach((activity) => {
                if (activity.type == ActivityTypes.Message) {
                    this._logger.log(`Bot: Text      = ${ activity.text }`);
                    this._logger.log(`     Speak     = ${ activity.speak }`);
                    this._logger.log(`     InputHint = ${ activity.inputHint }`);
                } else {
                    this._logger.log(`Bot: Activity = ${ activity.type }`);
                    JSON.stringify(activity,null,2).split(/\n/).forEach((line) =>{ this._logger.log(line); });
                }
            });
            let now = new Date();
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / actions / endTurn.ts View on Github external
public async continueDialog(dc: DialogContext): Promise {
        const activity = dc.context.activity;
        if (activity.type === ActivityTypes.Message) {
            return await dc.endDialog();
        } else {
            return Dialog.EndOfTurn;
        }
    }
}
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / src / prompts / oauthPrompt.ts View on Github external
token = context.activity.value as TokenResponse;
        } else if (this.isTeamsVerificationInvoke(context)) {
            const code: any = context.activity.value.state;
            try {
                token = await this.getUserToken(context, code);
                if (token !== undefined) {
                    await context.sendActivity({ type: 'invokeResponse', value: { status: 200 }});
                } else {
                    await context.sendActivity({ type: 'invokeResponse', value: { status: 404 }});
                }
            }
            catch (e)
            {
                await context.sendActivity({ type: 'invokeResponse', value: { status: 500 }});
            }
        } else if (context.activity.type === ActivityTypes.Message) {
            const matched: RegExpExecArray = /(\d{6})/.exec(context.activity.text);
            if (matched && matched.length > 1) {
                token = await this.getUserToken(context, matched[1]);
            }
        }

        return token !== undefined ? { succeeded: true, value: token } : { succeeded: false };
    }
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / conditions / onMessageActivity.ts View on Github external
constructor(actions: Dialog[] = [], condition?: string) {
        super(ActivityTypes.Message, actions, condition);
    }
}
github microsoft / botbuilder-js / libraries / botbuilder-dialogs-adaptive / src / activityProperty.ts View on Github external
public set value(value: Partial|string) {
        this._value = value;
        this._textTemplate = undefined;
        if (typeof value === 'string') {
            this._textTemplate = stringTemplate.compile(value);
        } else if (typeof value === 'object' && value.type === ActivityTypes.Message) {
            this._textTemplate = stringTemplate.compile(value.text);
        }
    }
github microsoft / botbuilder-js / libraries / botbuilder-planning / src / steps / waitForInput.ts View on Github external
processor: async (dc) => {
                const activity = dc.context.activity;
                if (activity.type === ActivityTypes.Message) {
                    return await dc.endDialog(activity.text || '');
                } else {
                    return Dialog.EndOfTurn;
                }
            }
        };