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 58 lines 1.43 KB
Raw
1 /**
2 * Triggers Example
3 *
4 * This example demonstrates how to use Composio SDK for triggers.
5 *
6 * Prerequisites:
7 * 1. Set up your COMPOSIO_API_KEY in the .env file
8 * 2. Install dependencies: pnpm install
9 * 3. Run the example: pnpm start
10 */
11
12 import { Composio } from '@composio/core';
13 import 'dotenv/config';
14
15 /**
16 * Initialize Composio
17 */
18 const composio = new Composio({
19 apiKey: process.env.COMPOSIO_API_KEY,
20 // baseURL: 'https://staging-backend.composio.dev',
21 });
22
23 /**
24 * Main function to run the example
25 */
26 async function main() {
27 try {
28 console.log('🚀 Starting Triggers Example...');
29
30 // Get available tools
31 const tools = await composio.tools.get('default', {
32 // Specify the toolkits you want to use
33 toolkits: ['gmail', 'googlecalendar'],
34 limit: 10,
35 });
36
37 console.log(`✅ Found ${tools.length} tools`);
38
39 // TODO: Add your example implementation here
40 console.log(
41 '📝 Go to https://app.composio.dev to create an app and add a trigger, Once you have an incoming trigger, you will see the events'
42 );
43
44 await composio.triggers.subscribe(data => {
45 console.log('🔔 Trigger received:', JSON.stringify(data, null, 2));
46 });
47 console.log('Subscribed to trigger events');
48 } catch (error) {
49 console.error('❌ Error running example:', error);
50 process.exitCode = 1;
51 }
52 }
53
54 // Run the example
55 main().catch(error => {
56 console.error(error);
57 process.exitCode = 1;
58 });