UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

72 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTestTurnContextAndState = void 0; exports.createTestInvoke = createTestInvoke; exports.createTestConversationUpdate = createTestConversationUpdate; const botbuilder_1 = require("botbuilder"); const TurnState_1 = require("../../TurnState"); /** * Creates, for testing, an invoke activity with the given name, value and data. * Compatible with botbuilder's TestAdapter. * @param {string} name - The name of the invoke activity. * @param {any} value - The value of the invoke activity. * @param {any} channelData - The bot's channel data of the invoke activity. * @returns {Activity} - The created invoke activity. */ function createTestInvoke(name, value, channelData = {}) { const activity = { type: botbuilder_1.ActivityTypes.Invoke, name, channelData, value, // Not sure why, but the TestAdapter returns nothing unless this prop is set deliveryMode: 'expectReplies' }; return activity; } /** * Creates a conversation update activity for testing. * Compatible with botbuilder's TestAdapter. * @param {any} channelData An object containing channel data * @returns {Partial<Activity>} A conversation update activity */ function createTestConversationUpdate(channelData = {}) { const activity = { type: botbuilder_1.ActivityTypes.ConversationUpdate, channelData }; return activity; } /** * Returns turn context and state for testing. * @remarks Compatible with botbuilder's TestAdapter and TeamsAdapter. Use _ on import if either value is not needed. For example, `const [context, _] = createTestTurnContextAndState(...)`. * @param {TeamsAdapter | TestAdapter} adapter - The adapter to use for the turn context * @param {Partial<Activity>} activity - The activity to use for the turn context * @returns {[TurnContext, TurnState]} - The created turn context and state. */ const createTestTurnContextAndState = async (adapter, activity) => { const context = new botbuilder_1.TurnContext(adapter, { channelId: 'msteams', recipient: { id: 'bot', name: 'Bot' }, from: { id: 'user', name: 'User' }, conversation: { id: 'convo', isGroup: false, conversationType: 'personal', name: 'convo' }, ...activity }); const state = new TurnState_1.TurnState(); await state.load(context); state.temp = { input: context.activity.text, inputFiles: context.activity.attachments, lastOutput: '', actionOutputs: {}, authTokens: {} }; return [context, state]; }; exports.createTestTurnContextAndState = createTestTurnContextAndState; //# sourceMappingURL=TestUtilities.js.map