Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { Composio } from '@composio/core'; |
| 2 | |
| 3 | // Initialize Composio client |
| 4 | const composio = new Composio({ |
| 5 | apiKey: process.env.COMPOSIO_API_KEY, |
| 6 | }); |
| 7 | |
| 8 | const connectedAccountId = process.env.COMPOSIO_EXAMPLES_GMAIL_CONNECTED_ACCOUNT_ID; // your Gmail connected account ID |
| 9 | const userId = process.env.COMPOSIO_EXAMPLES_USER_ID; // the user that owns the connected account |
| 10 | if (!connectedAccountId || !userId) { |
| 11 | throw new Error('Set COMPOSIO_EXAMPLES_GMAIL_CONNECTED_ACCOUNT_ID and COMPOSIO_EXAMPLES_USER_ID'); |
| 12 | } |
| 13 | |
| 14 | // create a trigger |
| 15 | const { triggerId } = await composio.triggers.create(userId, 'GMAIL_NEW_GMAIL_MESSAGE', { |
| 16 | connectedAccountId, |
| 17 | triggerConfig: {}, |
| 18 | }); |
| 19 | |
| 20 | // Subscribe to triggers with optional filters |
| 21 | const sub = await composio.triggers.subscribe( |
| 22 | metadata => { |
| 23 | console.log('Received trigger event:'); |
| 24 | console.dir(metadata, { depth: 3 }); |
| 25 | }, |
| 26 | { triggerId } |
| 27 | ); |
| 28 | |
| 29 | console.log('Subscribed to triggers. Waiting for events...'); |
| 30 | |
| 31 | // Keep the process alive forever |
| 32 | process.stdin.resume(); |