@astreus-ai/resend-plugin v0.1.0
Astreus Resend Plugin
An email integration plugin for the Astreus AI agent framework, allowing agents to send emails using Resend.
Features
- Official Resend API Integration: Uses the official Resend API for reliable email delivery
- Template Support: Send emails using pre-built templates with dynamic data
- Rich Email Content: Support for both HTML and plain text emails
- Flexible Recipients: Support for CC and BCC recipients
- Custom Sender Configuration: Configurable sender and reply-to addresses
- Enhanced Logging: Detailed logging of email operations for improved debugging
- Integration with Astreus Logger: Consistent logging patterns with the core framework
Installation
npm install @astreus-ai/resend-pluginConfiguration
Create a .env file with your Resend API configuration:
# Resend API configuration
RESEND_API_KEY=your_resend_api_key
RESEND_DEFAULT_FROM=you@example.com
RESEND_DEFAULT_REPLY_TO=optional_reply_to@example.com
# Logging options
LOG_LEVEL=info # Options: error, warn, info, debugTo get these values: 1. Create a Resend account at https://resend.com/ 2. Generate an API key from your Resend dashboard 3. Verify your sending domain
Usage
Basic Usage
import { createAgent } from 'astreus';
import ResendPlugin from '@astreus-ai/resend-plugin';
// Create a Resend plugin instance
const resendPlugin = new ResendPlugin();
// Initialize the plugin
await resendPlugin.init();
// Create an agent with the Resend plugin
const agent = await createAgent({
name: 'Email Agent',
description: 'An agent that can send emails',
plugins: [resendPlugin]
});
// Now the agent can use email functionality
const response = await agent.chat(`Send an email to john@example.com with subject "Welcome" and message "Hello, welcome to our service!"`);Custom Configuration
import { createAgent } from 'astreus';
import ResendPlugin from '@astreus-ai/resend-plugin';
// Create a plugin with custom configuration
const resendPlugin = new ResendPlugin({
apiKey: 'your_resend_api_key',
defaultFrom: 'you@example.com',
defaultReplyTo: 'reply@example.com',
logLevel: 'debug' // Set logging verbosity
});
// Initialize the plugin
await resendPlugin.init();
// Create an agent with the plugin
const agent = await createAgent({
name: 'Email Agent',
description: 'An agent that can send emails',
plugins: [resendPlugin]
});Available Tools
The Resend plugin provides the following tools to Astreus agents:
resend_send_email: Send a text or HTML email to recipientsresend_send_template_email: Send an email using a pre-built template with dynamic data
Send an Email
const response = await agent.execute('resend_send_email', {
to: 'recipient@example.com',
subject: 'Hello from Astreus',
html: '<h1>Hello World</h1><p>This is a test email from Astreus using Resend.</p>',
text: 'Hello World! This is a test email from Astreus using Resend.',
from: 'custom@example.com', // Optional, overrides default
replyTo: 'reply@example.com', // Optional, overrides default
cc: 'cc@example.com', // Optional
bcc: 'bcc@example.com' // Optional
});
console.log(`Email sent with ID: ${response.id}`);Send a Template Email
const response = await agent.execute('resend_send_template_email', {
to: 'recipient@example.com',
templateId: 'template_123abc',
templateData: {
name: 'John Doe',
verificationCode: '123456',
link: 'https://example.com/verify'
},
from: 'custom@example.com', // Optional, overrides default
replyTo: 'reply@example.com', // Optional, overrides default
cc: 'cc@example.com', // Optional
bcc: 'bcc@example.com' // Optional
});
console.log(`Template email sent with ID: ${response.id}`);Error Handling
The plugin methods throw descriptive errors when something goes wrong. Always wrap the calls in try/catch blocks:
try {
const response = await agent.execute('resend_send_email', { /* ... */ });
console.log(`Email sent with ID: ${response.id}`);
} catch (error) {
console.error('Failed to send email:', error.message);
}Debugging
The plugin includes logging capabilities to help troubleshoot issues. You can adjust the logging level using the LOG_LEVEL environment variable or by setting the logLevel option when creating the plugin instance.
Resend API Documentation
For more details on the Resend API, refer to the official documentation: Resend API Documentation
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
📬 Contact
Astreus Team - https://astreus.org
Project Link: https://github.com/astreus-ai/astreus-resend-plugin
6 months ago