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 | /** |
| 2 | * File-handling Example |
| 3 | * |
| 4 | * This example demonstrates how to use Composio SDK for file-handling. |
| 5 | * |
| 6 | * Prerequisites: |
| 7 | * 1. Set up your COMPOSIO_API_KEY in the .env file |
| 8 | * 3. Run the example: pnpm start |
| 9 | */ |
| 10 | |
| 11 | import { Composio } from '@composio/core'; |
| 12 | import { file } from 'bun'; |
| 13 | import 'dotenv/config'; |
| 14 | import path from 'path'; |
| 15 | |
| 16 | /** |
| 17 | * Initialize Composio |
| 18 | */ |
| 19 | const composio = new Composio({ |
| 20 | apiKey: process.env.COMPOSIO_API_KEY, |
| 21 | }); |
| 22 | |
| 23 | /** |
| 24 | * Main function to run the example |
| 25 | */ |
| 26 | async function main() { |
| 27 | try { |
| 28 | console.log('🚀 Starting File-handling Example...'); |
| 29 | |
| 30 | // Get available tools |
| 31 | const tools = await composio.tools.get('default', 'GMAIL_SEND_EMAIL'); |
| 32 | |
| 33 | console.log(`✅ Found ${tools.length} tools`); |
| 34 | |
| 35 | const filePath = |
| 36 | 'https://avatars.githubusercontent.com/u/128464815?v=4&id=sdsdjljkljlsdfjslkfjlksdjflkdjflksdjflksdfwfowdfk;dfkl;sdfk;slkf;lskf;lsdkf;lk'; |
| 37 | |
| 38 | console.log(`Sending file from ${filePath}`); |
| 39 | |
| 40 | const result = await composio.tools.execute('GMAIL_SEND_EMAIL', { |
| 41 | userId: 'default', |
| 42 | arguments: { |
| 43 | attachment: filePath, |
| 44 | recipient_email: 'musthaq@composio.dev', |
| 45 | user_id: 'me', |
| 46 | body: 'Hello, this is a test email with a file attachment.', |
| 47 | subject: 'Test Email with Attachment', |
| 48 | }, |
| 49 | }); |
| 50 | |
| 51 | console.log(JSON.stringify(result, null, 2)); |
| 52 | } catch (error) { |
| 53 | console.error('❌ Error running example:', error); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Run the example |
| 58 | main().catch(console.error); |