Overview
Plugins in elizaOS can expose HTTP routes that act as webhooks, allowing external services to trigger agent actions and send messages on behalf of agents. This enables powerful integrations with third-party services, automated workflows, and custom APIs.Defining Routes in Plugins
Routes are defined in your plugin’s main export using theroutes
property. Each route specifies an HTTP method, path, and handler function.
Route Interface
Basic Route Example
Sending Messages as an Agent
The most powerful use case for plugin routes is sending messages on behalf of the agent. This allows external services to make the agent speak in any conversation.Using the Messaging API
To send a message as an agent, your route handler needs to make a POST request to the messaging submit endpoint:Complete Example: GitHub Webhook Integration
Here’s a complete example of a plugin that receives GitHub webhooks and makes the agent comment on events:Advanced Patterns
Authenticated Webhooks
For secure webhook endpoints, implement authentication:File Upload Webhooks
For endpoints that accept file uploads:Scheduled Messages
Create endpoints that schedule future agent messages:Route Registration and Access
How Routes Are Registered
When your plugin is loaded:- The runtime registers all routes from the
routes
array - Routes are accessible at the path you specify
- The runtime provides the route handler with the agent’s runtime instance
Accessing Your Routes
Routes are available at:- Development:
http://localhost:3000{path}
- Production:
https://your-domain.com{path}
http://localhost:3000/webhook?agentId=YOUR_AGENT_ID
Best Practices
1. Security
- Always validate input from webhooks
- Implement authentication for sensitive endpoints
- Verify signatures from known services (GitHub, Stripe, etc.)
- Rate limit webhook endpoints to prevent abuse
2. Error Handling
- Return appropriate HTTP status codes
- Log errors for debugging
- Don’t expose internal errors to webhook callers
- Return 200 OK to prevent webhook retries for non-critical errors
3. Message Formatting
- Keep messages concise and relevant
- Use emoji sparingly for visual indicators
- Include links when referencing external resources
- Add metadata for message tracking and debugging
4. Performance
- Process webhooks asynchronously when possible
- Return responses quickly (< 5 seconds)
- Queue heavy processing tasks
- Implement timeouts for external API calls
Common Use Cases
- CI/CD Notifications: Deploy status, build results, test failures
- Monitoring Alerts: System health, error rates, performance metrics
- Customer Support: Ticket creation, status updates, escalations
- Social Media: Mentions, new followers, engagement metrics
- E-commerce: Order updates, inventory alerts, customer inquiries
- Calendar Integration: Meeting reminders, schedule changes
- IoT Devices: Sensor alerts, status updates, command responses
Testing Webhooks
Local Development
Use ngrok or similar tools to expose your local server:Testing with cURL
Testing Webhook Routes
ElizaOS provides two types of tests for validating webhook functionality: component tests and e2e tests.Component Tests
Component tests verify route handler logic in isolation:src/__tests__/webhook-routes.test.ts
E2E Tests
E2E tests validate the complete webhook flow with a live agent runtime:src/__tests__/webhook-e2e.test.ts
Adding Tests to Your Plugin
Include tests in your plugin definition:src/index.ts