newo
Version:
NEWO CLI: Professional command-line tool with modular architecture for NEWO AI Agent development. Features account migration, integration management, webhook automation, AKB knowledge base, project attributes, sandbox testing, IDN-based file management, r
83 lines ⢠3.75 kB
JavaScript
/**
* Webhook creation command handler
*/
import { makeClient } from '../../api.js';
import { getValidAccessToken } from '../../auth.js';
import { selectSingleCustomer } from '../customer-selection.js';
import { customerDir } from '../../fsutil.js';
import fs from 'fs-extra';
import yaml from 'js-yaml';
import path from 'path';
export async function handleCreateWebhooksCommand(customerConfig, args, verbose) {
const { selectedCustomer } = selectSingleCustomer(customerConfig, args.customer);
if (!selectedCustomer) {
console.error('ā No customer selected');
process.exit(1);
}
const accessToken = await getValidAccessToken(selectedCustomer);
const client = await makeClient(verbose, accessToken);
console.log(`\nš” Creating webhooks for ${selectedCustomer.idn}...\n`);
const custDir = customerDir(selectedCustomer.idn);
let outgoingCreated = 0;
let incomingCreated = 0;
// Create outgoing webhooks
const outgoingFile = path.join(custDir, 'integrations/api/connectors/webhook/webhooks/outgoing.yaml');
if (await fs.pathExists(outgoingFile)) {
const outgoingData = yaml.load(await fs.readFile(outgoingFile, 'utf8'));
const webhooks = outgoingData.webhooks || [];
console.log(`Found ${webhooks.length} outgoing webhooks in YAML file`);
for (const webhook of webhooks) {
try {
await client.post('/api/v1/webhooks', {
idn: webhook.idn,
description: webhook.description || '',
connector_idn: webhook.connector_idn,
url: webhook.url,
command_idns: webhook.command_idns || []
});
outgoingCreated++;
console.log(` ā
Created outgoing: ${webhook.idn}`);
}
catch (error) {
const status = error.response?.status;
if (status === 409) {
console.log(` ā¹ļø Already exists: ${webhook.idn}`);
}
else {
console.error(` ā Failed: ${webhook.idn} - ${error.response?.data?.reason || error.message}`);
}
}
}
}
// Create incoming webhooks
const incomingFile = path.join(custDir, 'integrations/api/connectors/webhook/webhooks/incoming.yaml');
if (await fs.pathExists(incomingFile)) {
const incomingData = yaml.load(await fs.readFile(incomingFile, 'utf8'));
const webhooks = incomingData.webhooks || [];
console.log(`\nFound ${webhooks.length} incoming webhooks in YAML file`);
for (const webhook of webhooks) {
try {
await client.post('/api/v1/webhooks/incoming', {
idn: webhook.idn,
description: webhook.description || '',
connector_idn: webhook.connector_idn,
event_idns: webhook.event_idns || [],
allowed_ips: webhook.allowed_ips || []
});
incomingCreated++;
console.log(` ā
Created incoming: ${webhook.idn}`);
}
catch (error) {
const status = error.response?.status;
if (status === 409) {
console.log(` ā¹ļø Already exists: ${webhook.idn}`);
}
else {
console.error(` ā Failed: ${webhook.idn} - ${error.response?.data?.reason || error.message}`);
}
}
}
}
console.log(`\nā
Created ${outgoingCreated} outgoing and ${incomingCreated} incoming webhooks\n`);
}
//# sourceMappingURL=create-webhooks.js.map