@devries-cameron20 / composio-1 / commits / 680d1ea01
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix trigger snippets

haxzie committed Jun 24, 2025 at 15:48 UTC 680d1ea0171e17b36074f183f82f85a7bfd6988b
2 files changed +47 -48
fern/pages/src/triggers/using-triggers.mdx
+14 -22
@@ -21,7 +21,7 @@ When these events take place, triggers capture relevant information and deliver
21
22 ## Creating a trigger
23
24 -Head to the any app that supports triggers, eg [Slack](https://app.composio.dev/app/slack) in the dashboard and enable the trigger of choice.
24 +Head to any app that supports triggers, such as [Slack](https://app.composio.dev/app/slack) in the dashboard and enable the trigger of choice.
25
26 <video
27 src="../../../assets/videos/enabling-triggers.mp4"
@@ -39,15 +39,13 @@ The [triggers page](https://app.composio.dev/active_triggers?page=1) will show y
39 <img src="../../../assets/images/manage-triggers.png" alt="Manage triggers" />
40 </Frame>
41
42 -You create triggers through the SDK as well.
43 -
44 -First, you can view the required configuration to make the trigger too as follows:
42 +You can also create triggers programmatically using the SDK. To get started, first view the required configuration for creating a trigger:
43
44 <CodeGroup>
45 <SnippetCode
46 src="fern/snippets/triggers/typescript/triggers.ts"
47 startLine={1}
50 - endLine={27}
48 + endLine={30}
49 title="TypeScript (new)"
50 />
51
@@ -69,8 +67,8 @@ print(instance)
67 ```
68 <SnippetCode
69 src="fern/snippets/triggers/typescript/triggers.ts"
72 - startLine={28}
73 - endLine={40}
70 + startLine={31}
71 + endLine={46}
72 title="TypeScript (new)"
73 />
74 </CodeGroup>
@@ -80,9 +78,9 @@ print(instance)
78 During development, you may not have a proper webhook setup -- so you can subscribe to triggers directly through the SDK.
79
80 You subscribe to multiple trigger events by configuring the filters.
83 -When you specify multiple multiple filters, _ALL_ of them must match for the trigger to be subscribed to.
81 +When you specify multiple filters, _ALL_ of them must match for the trigger to be subscribed to.
82
85 -This method uses websockets to subscribe to the trigger.
83 +This method uses WebSocket to subscribe to the trigger.
84
85 <CodeGroup>
86 ```python Python
@@ -109,8 +107,8 @@ print(instance)
107
108 <SnippetCode
109 src="fern/snippets/triggers/typescript/triggers.ts"
112 -startLine={42}
113 -endLine={53}
110 +startLine={49}
111 +endLine={60}
112 title="TypeScript (new)"
113 />
114
@@ -118,7 +116,7 @@ title="TypeScript (new)"
116
117
118 ## Subscribing to triggers through Webhooks
121 -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.
119 +For production environments, you can receive trigger events via webhooks. This requires configuring a publicly accessible URL where Composio can send event payloads. The URL should point to an endpoint in your application that processes these incoming webhook requests.
120
121 <Frame caption="Webhook setup" background="subtle">
122 <img src="../../../assets/images/setup-webhook.png" alt="Webhook setup" />
@@ -139,7 +137,7 @@ To receive trigger events via webhooks, you need to configure a publicly accessi
137 </CodeGroup>
138
139 ### Trigger payload types
142 -When subscribing to triggers, it is helpful to know the payload type recieved from the trigger. You can inspect the payload type by fetching the trigger type.
140 +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.
141
142 <CodeGroup>
143 ```python Python maxLines=60 wordWrap
@@ -158,13 +156,9 @@ console.log(triggerType.payload);
156
157 ## Subscribing to triggers through the SDK
158
161 -During development you may not have a proper webhook setup -- you can subscribe to triggers directly through the SDK.
162 -
163 -This uses websockets to subscribe to the trigger.
159 +During development, when you may not have a proper webhook setup, you can subscribe to triggers directly through the SDK. This implementation uses WebSocket to establish a real-time connection to the trigger.
160
165 -You subscribe to multiple trigger events by configuring the filters.
166 -
167 -When you specify multiple multiple filters, _ALL_ of them must match for the trigger to be subscribed to.
161 +You can subscribe to multiple trigger events by configuring filters. When specifying multiple filters, _ALL_ of them must match for the trigger to be subscribed to.
162
163 <CodeGroup>
164 ```python Python maxLines=60 wordWrap
@@ -196,9 +190,7 @@ await composio.triggers.subscribe(
190
191 ## Specifying trigger configuration
192
199 -In some cases, triggers require certain configuration to set the correct events. You can inspect and add these properties while enabling the triggers.
200 -
201 -The dashboard will show you the trigger configuration to fill in.
193 +Triggers often require specific configuration to properly handle events. You can inspect and configure these properties through both the dashboard and the SDK.
194
195 <Frame caption="Trigger configuration" background="subtle">
196 <img
fern/snippets/triggers/typescript/triggers.ts
+33 -26
@@ -2,35 +2,42 @@ import { Composio } from "@composio/core";
2
3 const composio = new Composio()
4
5 -composio.triggers.getType("GITHUB_STAR_ADDED_EVENT").then(triggerType => {
6 - console.log(JSON.stringify(triggerType.config, null, 2))
7 -})
8 -// {
9 -// "properties": {
10 -// "owner": {
11 -// "description": "Owner of the repository",
12 -// "title": "Owner",
13 -// "type": "string"
14 -// },
15 -// "repo": {
16 -// "description": "Repository name",
17 -// "title": "Repo",
18 -// "type": "string"
19 -// }
20 -// },
21 -// "required": [
22 -// "owner",
23 -// "repo"
24 -// ],
25 -// "title": "WebhookConfigSchema",
26 -// "type": "object"
27 -// }
5 +// Fetch the trigger details
6 +const triggerType = await composio.triggers.getType("GITHUB_STAR_ADDED_EVENT");
7 +console.log(JSON.stringify(triggerType.config, null, 2))
8 +/*--- Trigger config ---
9 +{
10 + "properties": {
11 + "owner": {
12 + "description": "Owner of the repository",
13 + "title": "Owner",
14 + "type": "string"
15 + },
16 + "repo": {
17 + "description": "Repository name",
18 + "title": "Repo",
19 + "type": "string"
20 + }
21 + },
22 + "required": [
23 + "owner",
24 + "repo"
25 + ],
26 + "title": "WebhookConfigSchema",
27 + "type": "object"
28 + }
29 +*/
30
31 const userId = "user@acme.com";
30 -const { items: connections } = await composio.connectedAccounts.list({ userIds: [userId] });
32 +// Fetch the connected account for the user
33 +const { items: connections } = await composio.connectedAccounts.list({
34 + userIds: [userId]
35 +});
36 +// Get the first connected account
37 const [{ id: connectedAccountId }] = connections;
32 -console.log(connectedAccountId);
33 -const createResponse = await composio.triggers.create("GITHUB_STAR_ADDED_EVENT", {
38 +
39 +// Create the trigger
40 +const createResponse = await composio.triggers.create(userId, "GITHUB_STAR_ADDED_EVENT", {
41 connectedAccountId,
42 triggerConfig: {
43 owner: "composiohq",