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 27 lines 1.07 KB
Raw
1 import { Composio } from '@composio/core';
2
3 // Initialize Composio
4 // OpenAI Provider is automatically installed and initialized
5 const composio = new Composio({
6 apiKey: process.env.COMPOSIO_API_KEY,
7 });
8
9 /**
10 * This is a coumpound flow which will initiate a connection request and wait for the user to authorize the toolkit
11 */
12 const connectionRequest = await composio.toolkits.authorize('default', 'github');
13 const redirectUrl = connectionRequest.redirectUrl;
14 /**
15 * If the redirectUrl is not null, it means that the user needs to visit the following URL to authorize the toolkit
16 */
17 if (redirectUrl) {
18 console.log(`⚠️ Please visit the following URL to authorize the toolkit: ${redirectUrl}`);
19 }
20 console.log('🔄 Waiting for connection...');
21 /**
22 * This will wait for the user to authorize the toolkit and then return the connected account
23 * Optionally, you can pass a timeout to the waitForConnection method
24 */
25 const connectedAccount = await connectionRequest.waitForConnection();
26 console.log(`✅ Connected account created: ${connectedAccount.id}`);
27 console.log(connectedAccount);