How to use the botbuilder-core.TurnContext.applyConversationReference 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 / botDebugger.ts View on Github external
protected createEmulatorContext(session: ConversationReference): TurnContext {
		// Get emulators adapter
		const emulator = this.findAdapter('emulator');
		if (!emulator) {
			throw new Error(`BotDebugger: Cannot log debug activity to emulator. Adapter not found.`)
		}

		// Create request with session address
		const request = TurnContext.applyConversationReference({
			type: ActivityTypes.Event,
			name: 'debuggerSession'
		}, session);

		// Return context for session
		return new TurnContext(emulator, request);
	}
github microsoft / BotBuilder-Samples / samples / typescript_nodejs / 01.console-echo / src / consoleAdapter.ts View on Github external
public continueConversation(reference: ConversationReference, logic: (context: TurnContext) => Promise): Promise {
            // Create context and run middleware pipe
            const activity: Partial = TurnContext.applyConversationReference({}, reference, true);
            const context: TurnContext = new TurnContext(this, activity);

            return this.runMiddleware(context, logic)
                       .catch((err: Error) => { this.printError(err.toString()); });
    }
github microsoft / botbuilder-js / libraries / botbuilder / src / skills / skillHandler.ts View on Github external
const callback = async (context: TurnContext): Promise => {
            const adapter: BotFrameworkAdapter = (context.adapter as BotFrameworkAdapter);
            // Cache the ClaimsIdentity and ConnectorClient on the context so that it's available inside of the bot's logic.
            context.turnState.set(adapter.BotIdentityKey, claimsIdentity);
            context.turnState.set(this.SkillConversationReferenceKey, skillConversationReference);
            activity = TurnContext.applyConversationReference(activity, conversationReference) as Activity;
            const client = adapter.createConnectorClient(activity.serviceUrl);
            context.turnState.set(adapter.ConnectorClientKey, client);

            context.activity.id = replyToActivityId;
            switch (activity.type) {
                case ActivityTypes.EndOfConversation:
                    await this.conversationIdFactory.deleteConversationReference(conversationId);
                    SkillHandler.applyEoCToTurnContextActivity(context, activity);
                    await this.bot.run(context);
                    break;
                case ActivityTypes.Event:
                    SkillHandler.applyEventToTurnContextActivity(context, activity);
                    await this.bot.run(context);
                    break;
                default:
                    await context.sendActivity(activity);
github microsoft / botbuilder-js / libraries / botbuilder-skills / src / skillHostAdapter.ts View on Github external
public async forwardActivity(context: TurnContext, skillId: string, activity: Partial, skillConversation?: Partial): Promise {
        // Lookup skill by ID
        const skill = this._skills[skillId];
        if (skill == undefined) { throw new Error(`SkillHostAdapter.forwardActivity: a skill with an id of '${skillId}' not found.`) }

        // Clone activity and optionally apply skills conversation reference
        const clone: Partial = Object.assign({}, activity);
        if (skillConversation) { TurnContext.applyConversationReference(clone, skillConversation) }

        // Raise event
        await this.emitForwardActivity(context, skillId, clone, async () => {
            // POST activity to skill
            // - TODO: add auth headers
            const response = await fetch(skill.endpointUrl, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(clone)
            });

            // Check delivery status
            if (response.status >= 400) { throw new Error(`SkillHostAdapter.forwardActivity: '${response.status}' error forwarding activity to skill '${skillId}'.`) }
        });
github microsoft / botbuilder-js / libraries / botbuilder / src / botFrameworkAdapter.ts View on Github external
const client: ConnectorClient = this.createConnectorClient(reference.serviceUrl);

        // Mix in the tenant ID if specified. This is required for MS Teams.
        if (reference.conversation && reference.conversation.tenantId) {
            // Putting tenantId in channelData is a temporary solution while we wait for the Teams API to be updated
            parameters.channelData = { tenant: { id: reference.conversation.tenantId } };

            // Permanent solution is to put tenantId in parameters.tenantId
            parameters.tenantId = reference.conversation.tenantId;

        }

        const response = await client.conversations.createConversation(parameters);

        // Initialize request and copy over new conversation ID and updated serviceUrl.
        const request: Partial = TurnContext.applyConversationReference(
            { type: 'event', name: 'createConversation' },
            reference,
            true
        );

        const conversation: ConversationAccount = {
            id: response.id,
            isGroup: false,
            conversationType: null,
            tenantId: reference.conversation.tenantId,
            name: null,
        };
        request.conversation = conversation;
        request.channelData = parameters.channelData;

        if (response.serviceUrl) { request.serviceUrl = response.serviceUrl; }
github microsoft / botbuilder-js / libraries / botbuilder / src / botFrameworkAdapter.ts View on Github external
public async continueConversation(reference: Partial, logic: (context: TurnContext) => Promise): Promise {
        const request: Partial = TurnContext.applyConversationReference(
            { type: 'event', name: 'continueConversation' },
            reference,
            true
        );
        const context: TurnContext = this.createContext(request);

        await this.runMiddleware(context, logic as any);
    }