Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 24 lines 803 Bytes
Raw
1 import { Composio } from '@composio/core';
2
3 const composio = new Composio({
4 apiKey: process.env.COMPOSIO_API_KEY,
5 });
6
7 // fetch a trigger type
8 const triggerType = await composio.triggers.getType('GMAIL_NEW_GMAIL_MESSAGE');
9
10 console.log(JSON.stringify(triggerType, null, 2));
11
12 const connectedAccountId = process.env.COMPOSIO_EXAMPLES_GMAIL_CONNECTED_ACCOUNT_ID; // your Gmail connected account ID
13 const userId = process.env.COMPOSIO_EXAMPLES_USER_ID; // the user that owns the connected account
14 if (!connectedAccountId || !userId) {
15 throw new Error('Set COMPOSIO_EXAMPLES_GMAIL_CONNECTED_ACCOUNT_ID and COMPOSIO_EXAMPLES_USER_ID');
16 }
17
18 // create a trigger
19 const trigger = await composio.triggers.create(userId, triggerType.slug, {
20 connectedAccountId,
21 triggerConfig: {},
22 });
23
24 console.log(trigger);