Using Triggers

Send payloads to your AI agents or systems based on events in apps.

Triggers act as a notification system for your AI applications, enabling your agents to respond dynamically to external events occurring within your apps.

When these events take place, triggers capture relevant information and deliver structured payloads directly to your system, letting you build agents that respond proactively.

Triggers Overview

Triggers through Composio
Prerequisites

Before proceeding, ensure you’ve created an auth config and established a connection to an app (e.g., Slack, GitHub).

Creating a trigger

Head to any app that supports triggers, such as Slack in the dashboard and enable the trigger of choice.

Manage triggers
Triggers page

In some cases, triggers require certain configuration to set the correct events. You can inspect and add these properties while enabling the triggers.

The dashboard will show you the trigger configuration to fill in.

Trigger configuration
Trigger configuration

The triggers page will show you all the triggers that are enabled for your account.

Subscribing to triggers

The typical and recommended way to subscribe to triggers is through webhooks.

To receive trigger events via webhooks, you need to configure a publicly accessible URL where Composio can send the event payloads. This URL should point to an endpoint in your application that can process incoming webhook requests.

Use ngrok/webhook.site for local dev!

During development, you can use ngrok/webhook.site or other services to expose your local server to the internet.

Webhook setup
Webhook setup

Below are some examples of how to listen in on trigger events for a FastAPI/Next.js application.

1from fastapi import FastAPI, Request
2from typing import Dict, Any
3import uvicorn
4import json
5
6app = FastAPI(title="Webhook Demo")
7
8@app.post("/webhook")
9async def webhook_handler(request: Request):
10 # Get the raw payload
11 payload = await request.json()
12
13 # Log the received webhook data
14 print("Received webhook payload:")
15 print(json.dumps(payload, indent=2))
16
17 # Return a success response
18 return {"status": "success", "message": "Webhook received"}
19
20if __name__ == "__main__":
21 uvicorn.run(app, host="0.0.0.0", port=8000)

Trigger payload types

When subscribing to triggers, it is helpful to know the payload type received from the trigger. You can inspect the payload type by fetching the trigger type.

1# Get a trigger by id
2trigger = composio.triggers.get_type(slug="GITHUB_COMMIT_EVENT")
3print(trigger.payload)

Prototyping triggers during development

During development, you may not have a proper webhook setup — so you can subscribe to triggers directly through the SDK.

You subscribe to multiple trigger events by configuring the filters. When you specify multiple filters, ALL of them must match for the trigger to be subscribed to.

This method uses WebSocket to subscribe to the trigger.

1user_id = "user@email.com"
2
3# Subscribe to a trigger
4subscription = composio.triggers.subscribe()
5
6# Define a handler
7@subscription.handle(toolkit="GITHUB", user_id=user_id)
8def handle_github_event(data):
9 print(data)

Enabling/Disabling triggers

In cases where the trigger isn’t required for the system, it can be disabled.

1# Disable a trigger instance
2disabled_instance = composio.triggers.disable(trigger_id="ti_abcd123")
3print(disabled_instance)

If needed, the trigger can be enabled again.

1# Enable a trigger instance
2enabled_instance = composio.triggers.enable(trigger_id="ti_abcd123")
3print(enabled_instance)

Troubleshooting

If you encounter issues with triggers or webhook listeners, you can use the Composio dashboard to inspect detailed trigger logs. The dashboard allows you to review event payloads, identify errors, and manually resend events for testing purposes.

Access the trigger logs here.

Trigger logs
Trigger logs