How to use the botframework-schema.ActivityTypes.Event 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 / botframework-solutions / lib / typescript / botbuilder-skills / src / http / skillHttpBotAdapter.ts View on Github external
public async sendRemoteTokenRequestEvent(turnContext: TurnContext): Promise {
        // We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
        const response: Activity = ActivityExtensions.createReply(turnContext.activity);
        response.type = ActivityTypes.Event;
        response.name = 'tokens/request';

        // Send the tokens/request Event
        await this.sendActivities(turnContext, [response]);
    }
}
github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / skillMiddleware.ts View on Github external
public async onTurn(turnContext: TurnContext, next: () => Promise): Promise {
        const activity: Activity = turnContext.activity;

        if (activity !== undefined && activity.type === ActivityTypes.Event) {
            if (activity.name === SkillEvents.cancelAllSkillDialogsEventName) {

                // when skill receives a CancelAllSkillDialogsEvent, clear the dialog stack and short-circuit
                const currentConversation: DialogState|undefined = await this.dialogStateAccessor.get(turnContext, { dialogStack: [] });
                if (currentConversation !== undefined) {
                    currentConversation.dialogStack = [];
                    await this.dialogStateAccessor.set(turnContext, currentConversation);
                    await this.conversationState.saveChanges(turnContext, true);
                }

                return;
            }
        }

        await next();
    }
github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / websocket / skillWebSocketBotAdapter.ts View on Github external
public async sendRemoteTokenRequestEvent(turnContext: TurnContext): Promise {
        // We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
        const response: Activity = ActivityExtensions.createReply(turnContext.activity);
        response.type = ActivityTypes.Event;
        response.name = TokenEvents.tokenRequestEventName;

        // Send the tokens/request Event
        await this.sendActivities(turnContext, [response]);
    }
github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / skillCallingRequestHandler.ts View on Github external
action: async (request: ReceiveRequest, routeData: Object): Promise => {
                    // MISSING Check response converter
                    const bodyParts: string[] = await Promise.all(request.Streams.map
                    ((s: ContentStream): Promise => s.readAsJson()));
                    const body: string = bodyParts.join();
                    // eslint-disable-next-line @typescript-eslint/tslint/config
                    const activity: Activity = JSON.parse(body);
                    if (activity === undefined) {
                        throw new Error('Error deserializing activity response!');
                    }

                    if (activity.type === ActivityTypes.Event && activity.name === TokenEvents.tokenRequestEventName) {
                        if (this.tokenRequestHandler !== undefined) {
                            await this.tokenRequestHandler(activity);

                            return { id: '' };
                        } else {
                            throw new Error('Skill is requesting for token but there\'s no handler on the calling side!');
                        }
                    } else if (activity.type === ActivityTypes.Handoff) {
                        if (this.handoffActivityHandler !== undefined) {
                            await this.handoffActivityHandler(activity);

                            return { id: '' };
                        } else {
                            throw new Error('Skill is sending handoff activity but there\'s no handler on the calling side!');
                        }
                    } else {
github microsoft / botframework-solutions / lib / typescript / botbuilder-solutions / src / middleware / eventDebuggerMiddleware.ts View on Github external
public async onTurn(turnContext: TurnContext, next: () => Promise): Promise {
        const activity: Activity = turnContext.activity;

        if (activity.type === ActivityTypes.Message) {
            const text: string = activity.text;
            const value: string = JSON.stringify(activity.value);

            if (text && text.startsWith('/event:')) {
                const json: string = text.substr('/event:'.length);
                // eslint-disable-next-line @typescript-eslint/tslint/config
                const body: Activity = JSON.parse(json);

                turnContext.activity.type = ActivityTypes.Event;
                turnContext.activity.name = body.name || turnContext.activity.name;
                turnContext.activity.text = body.text || turnContext.activity.text;
                turnContext.activity.value = body.value || turnContext.activity.value;
            }

            if (value && value.includes('event')) {
                // eslint-disable-next-line @typescript-eslint/tslint/config
                const body: { event: { name: string; text: string; value: string }} = JSON.parse(value);

                turnContext.activity.type = ActivityTypes.Event;
                if (body.event !== undefined) {
                    if (body.event.name !== undefined) {
                        turnContext.activity.name = body.event.name;
                    }
                    if (body.event.text !== undefined) {
                        turnContext.activity.text = body.event.text;
github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / websocket / skillWebSocketTransport.ts View on Github external
public async cancelRemoteDialogs(turnContext: TurnContext): Promise {
        const cancelRemoteDialogEvent: Activity = ActivityExtensions.createReply(turnContext.activity);
        cancelRemoteDialogEvent.type = ActivityTypes.Event;
        cancelRemoteDialogEvent.name = SkillEvents.cancelAllSkillDialogsEventName;

        await this.forwardToSkill(turnContext, cancelRemoteDialogEvent);
    }
github microsoft / botframework-solutions / sdk / typescript / libraries / botbuilder-solutions / src / middleware / eventDebuggerMiddleware.ts View on Github external
const value: string = JSON.stringify(activity.value);

            if (text && text.startsWith('/event:')) {
                const json: string = text.substr('/event:'.length);
                const body: Activity = JSON.parse(json);

                turnContext.activity.type = ActivityTypes.Event;
                turnContext.activity.name = body.name || turnContext.activity.name;
                turnContext.activity.text = body.text || turnContext.activity.text;
                turnContext.activity.value = body.value || turnContext.activity.value;
            }

            if (value && value.includes('event')) {
                const body: { event: { name: string; text: string; value: string }} = JSON.parse(value);

                turnContext.activity.type = ActivityTypes.Event;
                if (body.event !== undefined) {
                    if (body.event.name !== undefined) {
                        turnContext.activity.name = body.event.name;
                    }
                    if (body.event.text !== undefined) {
                        turnContext.activity.text = body.event.text;
                    }
                    if (body.event.value !== undefined) {
                        turnContext.activity.value = body.event.value;
                    }
                }
            }
        }

        return next();
    }
github microsoft / botframework-solutions / lib / typescript / botbuilder-solutions / src / dialogs / eventPrompt.ts View on Github external
protected async onRecognize(context: TurnContext, state: object, options: PromptOptions): Promise> {
        const result: PromptRecognizerResult = { succeeded: false };
        const activity: Activity = context.activity;

        if (activity.type === ActivityTypes.Event && activity.name === this.eventName) {
            result.succeeded = true;
            result.value = activity;
        }

        return Promise.resolve(result);
    }
}
github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / http / skillHttpTransport.ts View on Github external
public async cancelRemoteDialogs(turnContext: TurnContext): Promise {
        const cancelRemoteDialogEvent: Activity = ActivityExtensions.createReply(turnContext.activity);
        cancelRemoteDialogEvent.type = ActivityTypes.Event;
        cancelRemoteDialogEvent.name = SkillEvents.cancelAllSkillDialogsEventName;

        await this.forwardToSkill(turnContext, cancelRemoteDialogEvent);
    }