From 9efef46050764044c21b712e62eda4e76b3d0872 Mon Sep 17 00:00:00 2001 From: Apoorv Taneja Date: Thu, 12 Dec 2024 21:57:40 +0530 Subject: [PATCH] fix: Triggers parity (#1003) --- js/src/cli/triggers.ts | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/js/src/cli/triggers.ts b/js/src/cli/triggers.ts index 162383a280d..9508156f188 100644 --- a/js/src/cli/triggers.ts +++ b/js/src/cli/triggers.ts @@ -1,6 +1,7 @@ /* eslint-disable no-console */ import chalk from "chalk"; import { Command } from "commander"; +import client from "../sdk/client/client"; import { getOpenAPIClient } from "../sdk/utils/config"; import { Composio } from "../sdk"; @@ -38,6 +39,8 @@ export default class ConnectionsCommand { new TriggerAdd(command); new TriggerDisable(command); new ActiveTriggers(command); + new TriggerEnable(command); + new TriggerCallback(command); } private async handleAction(options: { @@ -176,6 +179,29 @@ export class TriggerDisable { } } +export class TriggerEnable { + private program: Command; + constructor(program: Command) { + this.program = program; + + this.program + .command("enable") + .description("Enable an existing trigger") + .argument("", "The trigger id") + .action(this.handleAction.bind(this)); + } + + async handleAction(triggerId: string): Promise { + const composioClient = new Composio(); + try { + await composioClient.triggers.enable({ triggerId }); + console.log(chalk.green(`Trigger ${triggerId} enabled`)); + } catch (error) { + console.log(chalk.red(`Error enabling trigger ${triggerId}: ${error}`)); + } + } +} + export class ActiveTriggers { private program: Command; constructor(program: Command, register: boolean = true) { @@ -203,3 +229,57 @@ export class ActiveTriggers { } } } + +export class TriggerCallback { + private program: Command; + constructor(program: Command) { + this.program = program; + + const callbackCommand = this.program + .command("callback") + .description("Manage trigger callback URLs"); + + callbackCommand + .command("set") + .description("Set a callback URL for a trigger") + .argument("", "Callback URL that needs to be set") + .action(this.handleSetAction.bind(this)); + + callbackCommand + .command("get") + .description("Get the current callback URL for a trigger") + .action(this.handleGetAction.bind(this)); + } + + async handleSetAction(callbackURL: string): Promise { + getOpenAPIClient(); + try { + await client.triggers.setCallbackUrl({ + body: { + callbackURL: callbackURL, + }, + }); + console.log(chalk.green(`Callback URL set to ${callbackURL}`)); + } catch (error) { + console.log( + chalk.red( + `Error setting callback URL to ${callbackURL}: ${(error as Error).message}` + ) + ); + } + } + + async handleGetAction(): Promise { + getOpenAPIClient(); + try { + const res = await client.triggers.getWebhookUrl(); + console.log( + chalk.green(`Current callback URL is ${res?.data?.callbackURL}`) + ); + } catch (error) { + console.log( + chalk.red(`Error getting callback URL: ${(error as Error).message}`) + ); + } + } +}