How to use the botframework-schema.ActivityTypes function in botframework-schema

To help you get started, we’ve selected a few botframework-schema 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-js / libraries / botbuilder-core / lib / testAdapter.js View on Github external
receiveActivity(activity) {
        // Initialize request
        const request = Object.assign({}, this.template, typeof activity === 'string' ? { type: botframework_schema_1.ActivityTypes.Message, text: activity } : activity);
        if (!request.type) {
            request.type = botframework_schema_1.ActivityTypes.Message;
        }
        if (!request.id) {
            request.id = (this.nextId++).toString();
        }
        // Create context object and run middleware
        const context = new turnContext_1.TurnContext(this, request);
        return this.runMiddleware(context, this.logic);
    }
    /**
github microsoft / botbuilder-js / libraries / botbuilder / lib / testAdapter.js View on Github external
let myInterval = setInterval(() => {
                    let current = new Date().getTime();
                    if ((current - start) > timeout) {
                        let expectedActivity = (typeof expected === 'string' ? { type: botframework_schema_1.ActivityTypes.Message, text: expected } : expected);
                        throw new Error(`${timeout}ms Timed out waiting for:${description || expectedActivity.text}`);
                    }
                    // if we have replies
                    if (this.adapter.botReplies.length > 0) {
                        clearInterval(myInterval);
                        let botReply = this.adapter.botReplies[0];
                        this.adapter.botReplies.splice(0, 1);
                        if (typeof expected === 'function') {
                            expected(botReply, description);
                        }
                        else if (typeof expected === 'string') {
                            assert.equal(botReply.type, botframework_schema_1.ActivityTypes.Message, (description || '') + ` type === '${botReply.type}'. `);
                            assert.equal(botReply.text, expected, (description || '') + ` text === "${botReply.text}"`);
                        }
                        else {
                            this.validateActivity(botReply, expected);
                        }
                        resolve();
                        return;
                    }
                }, interval);
            });
github microsoft / botbuilder-js / libraries / botbuilder-core / lib / transcriptLogger.js View on Github external
context.onDeleteActivity((ctx, reference, next) => {
            // run full pipeline
            next();
            // add MessageDelete activity
            // log as MessageDelete activity
            let deleteActivity = turnContext_1.TurnContext.applyConversationReference({
                type: botframework_schema_1.ActivityTypes.MessageDelete,
                id: reference.activityId
            }, reference, false);
            this.logActivity(deleteActivity);
        });
        // process bot logic
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / lib / 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 === botframework_schema_1.ActivityTypes.Message) {
            // Create dialog context.
            const dc = await this.dialogs.createContext(turnContext);
            const utterance = (turnContext.activity.text || '').trim().toLowerCase();
            if (utterance === 'cancel') {
                if (dc.activeDialog) {
                    await dc.cancelAllDialogs();
                    await dc.context.sendActivity(`Ok... canceled.`);
                }
                else {
                    await dc.context.sendActivity(`Nothing to cancel.`);
                }
            }
            if (!dc.context.responded) {
                // Continue the current dialog if one is pending.
                await dc.continueDialog();
            }
github microsoft / botbuilder-js / libraries / botbuilder / lib / bot.js View on Github external
post(context, ...activities) {
        // Ensure activities are well formed.
        for (let i = 0; i < activities.length; i++) {
            let activity = activities[i];
            if (!activity.type) {
                activity.type = botframework_schema_1.ActivityTypes.Message;
            }
            botContext_1.applyConversationReference(activity, context.conversationReference);
        }
        // Run post activity pipeline
        const adapter = this.adapter;
        return this.postActivity(context, activities, function postActivities() {
            // Post the set of output activities
            return adapter.post(activities)
                .then((responses) => {
                // Ensure responses array populated
                if (!Array.isArray(responses)) {
                    let mockResponses = [];
                    for (let i = 0; i < activities.length; i++) {
                        mockResponses.push({});
                    }
                    return mockResponses;
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / lib / bot.js View on Github external
await dc.context.sendActivity(`Ok... canceled.`);
                }
                else {
                    await dc.context.sendActivity(`Nothing to cancel.`);
                }
            }
            if (!dc.context.responded) {
                // Continue the current dialog if one is pending.
                await dc.continueDialog();
            }
            if (!dc.context.responded) {
                // If no response has been sent, start the onboarding dialog.
                await dc.beginDialog('root');
            }
        }
        else if (turnContext.activity.type === botframework_schema_1.ActivityTypes.ConversationUpdate &&
            turnContext.activity.membersAdded[0].name !== 'Bot') {
            // Send a "this is what the bot does" message.
            const description = [
                'This is a bot that demonstrates an alternate dialog system',
                'which uses a slot filling technique to collect multiple responses from a user.',
                'Say anything to continue.'
            ];
            await turnContext.sendActivity(description.join(' '));
        }
        await this.conversationState.saveChanges(turnContext);
    }
}
github microsoft / botbuilder-js / libraries / botbuilder / lib / botContext.js View on Github external
context.reply = function reply(textOrActivity, speak, additional) {
        throwIfDisposed('reply');
        // Check other parameters
        if (!additional && typeof speak === 'object') {
            additional = speak;
            speak = undefined;
        }
        if (typeof textOrActivity === 'object') {
            if (!textOrActivity.type) {
                textOrActivity.type = botframework_schema_1.ActivityTypes.Message;
            }
            this.responses.push(textOrActivity);
        }
        else {
            const activity = Object.assign({
                type: botframework_schema_1.ActivityTypes.Message,
                text: textOrActivity || '',
            }, additional || {});
            if (typeof speak === 'string') {
                activity.speak = speak;
            }
            this.responses.push(activity);
        }
        return this;
    };
    context.replyWith = function replyWith(templateId, data) {
github microsoft / botbuilder-js / libraries / botbuilder-core / lib / turnContext.js View on Github external
const output = activities.map((a) => {
            const o = TurnContext.applyConversationReference(Object.assign({}, a), ref);
            if (!o.type) {
                o.type = botframework_schema_1.ActivityTypes.Message;
            }
            if (o.type !== botframework_schema_1.ActivityTypes.Trace) {
                sentNonTraceActivity = true;
            }
            return o;
        });
        return this.emit(this._onSendActivities, output, () => {
github microsoft / botbuilder-js / libraries / botbuilder-core / lib / messageFactory.js View on Github external
static text(text, speak, inputHint) {
        const msg = {
            type: botframework_schema_1.ActivityTypes.Message,
            text: text,
            inputHint: inputHint || botframework_schema_1.InputHints.AcceptingInput
        };
        if (speak) {
            msg.speak = speak;
        }
        return msg;
    }
    /**
github microsoft / botbuilder-js / libraries / botbuilder / lib / templateManager.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            for (var renderer of this.templateRenderers) {
                let templateOutput = yield renderer.renderTemplate(context, language, templateId, data);
                if (templateOutput) {
                    if (typeof templateOutput === 'object') {
                        if (!templateOutput.type) {
                            templateOutput.type = botframework_schema_1.ActivityTypes.Message;
                        }
                        return templateOutput;
                    }
                    else {
                        const activity = {
                            type: botframework_schema_1.ActivityTypes.Message,
                            text: templateOutput || '',
                        };
                        return activity;
                    }
                }
            }
            return undefined;
        });
    }