UNPKG

n8n

Version:

n8n Workflow Automation Tool

58 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildConfigureChannelTool = buildConfigureChannelTool; const tool_1 = require("@n8n/agents/tool"); const api_types_1 = require("@n8n/api-types"); const telemetry_1 = require("@n8n/telemetry"); const nanoid_1 = require("nanoid"); const zod_1 = require("zod"); const configureChannelInputSchema = zod_1.z.object({ integrationType: zod_1.z.string().describe('Chat platform type from list_integration_types'), }); function buildConfigureChannelTool(deps) { return new tool_1.Tool(api_types_1.CONFIGURE_CHANNEL_TOOL_NAME) .description('Connect one available chat channel to the target agent. First call ' + 'list_integration_types and pass a returned `type` as `integrationType`; do not infer ' + 'channel names. Shows setup UI in chat where the user creates a new channel credential ' + 'or skips. The setup UI persists the connection, so use this for channel credentials ' + 'instead of the credentials tool or config writes. Returns { connected: boolean } (plus configMutated/agentId refresh metadata when connected); if ' + 'false, continue without the channel and do not re-prompt.') .input(configureChannelInputSchema) .suspend(api_types_1.channelSuspendPayloadSchema) .resume(api_types_1.channelResumeSchema) .handler(async ({ integrationType }, ctx) => { if (ctx.resumeData !== undefined && ctx.resumeData !== null) { if (ctx.resumeData.approved) { deps.track(telemetry_1.TELEMETRY_EVENT.AGENTS.BUILDER_ADDED_TRIGGER, { trigger_type: integrationType, }); } return { connected: ctx.resumeData.approved }; } const availableTypes = deps.listChatIntegrationTypes(); if (!availableTypes.includes(integrationType)) { const availableMessage = availableTypes.length ? ` Available: ${availableTypes.join(', ')}.` : ' No chat channels are currently available.'; return { ok: false, errors: [ { message: `Unsupported chat channel "${integrationType}". Call list_integration_types ` + 'and choose a returned type.' + availableMessage, }, ], }; } return await ctx.suspend({ requestId: (0, nanoid_1.nanoid)(), message: `Set up the ${integrationType} channel`, severity: 'info', channelConfig: { integrationType, agentId: deps.agentId }, projectId: deps.projectId, }); }) .build(); } //# sourceMappingURL=configure-channel.tool.js.map