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(core): loosen V3 webhook schema to accept any composio.* event type
jkomyno committed
Feb 2, 2026 at 22:56 UTC
eec30b0191d53bf3efe8f648e71145a9dc8b52f5
4 files changed
+89
-11
python/composio/core/models/triggers.py
+5
-3
@@ -126,7 +126,7 @@ class WebhookPayloadV3(te.TypedDict):
126
127
id: str
128
timestamp: str
129
- type: t.Literal["composio.trigger.message"]
129
+ type: str # Any composio.* event type (e.g., 'composio.trigger.message', 'composio.connected_account.expired')
130
metadata: WebhookPayloadV3Metadata
131
data: t.Dict[str, t.Any]
132
@@ -1074,7 +1074,7 @@ class Triggers(Resource):
1074
f"Failed to parse webhook payload as JSON: {e}"
1075
) from e
1076
1077
- # Try V3 first (has 'type' === 'composio.trigger.message' and 'metadata')
1077
+ # Try V3 first (has 'type' starting with 'composio.' and 'metadata')
1078
# Validate metadata is a dict with all required fields (matching TypeScript's zod schema)
1079
v3_metadata = data.get("metadata") if isinstance(data, dict) else None
1080
v3_metadata_valid = (
@@ -1086,9 +1086,11 @@ class Triggers(Resource):
1086
and "auth_config_id" in v3_metadata
1087
and "user_id" in v3_metadata
1088
)
1089
+ v3_type = data.get("type", "") if isinstance(data, dict) else ""
1090
if (
1091
isinstance(data, dict)
1091
- and data.get("type") == "composio.trigger.message"
1092
+ and isinstance(v3_type, str)
1093
+ and v3_type.startswith("composio.")
1094
and v3_metadata_valid
1095
and "id" in data
1096
and "data" in data
python/tests/test_triggers.py
+40
@@ -575,6 +575,46 @@ class TestVerifyWebhook:
575
result["payload"]["metadata"]["connected_account"]["user_id"] == "user-456"
576
)
577
578
+ def test_verify_webhook_v3_non_trigger_event_type(
579
+ self, triggers, test_secret, test_webhook_id, test_timestamp
580
+ ):
581
+ """Test V3 payload with non-trigger event type is detected as V3, not V2.
582
+
583
+ This is a regression test for PLEN-1397: V3 payloads with event types
584
+ other than 'composio.trigger.message' should still be detected as V3.
585
+ """
586
+ # V3 payload with a different event type
587
+ payload_dict = {
588
+ "id": "msg_abc123",
589
+ "timestamp": "2024-01-01T00:00:00Z",
590
+ "type": "composio.connected_account.expired", # Not 'composio.trigger.message'
591
+ "metadata": {
592
+ "log_id": "log-123",
593
+ "trigger_slug": "",
594
+ "trigger_id": "",
595
+ "connected_account_id": "conn-123",
596
+ "auth_config_id": "auth-123",
597
+ "user_id": "user-456",
598
+ },
599
+ "data": {"reason": "token_expired"},
600
+ }
601
+ payload = json.dumps(payload_dict)
602
+ signature = self.create_signature(
603
+ test_webhook_id, test_timestamp, payload, test_secret
604
+ )
605
+
606
+ result = triggers.verify_webhook(
607
+ id=test_webhook_id,
608
+ payload=payload,
609
+ signature=signature,
610
+ timestamp=test_timestamp,
611
+ secret=test_secret,
612
+ )
613
+
614
+ # Should be detected as V3, not fall back to V2
615
+ assert result["version"] == WebhookVersion.V3
616
+ assert result["raw_payload"] == payload_dict
617
+
618
# Successful verification with V2 payload
619
620
def test_verify_webhook_v2_payload(
ts/packages/core/src/types/triggers.types.ts
+12
-8
@@ -231,15 +231,19 @@ export type WebhookPayloadV2 = z.infer<typeof WebhookPayloadV2Schema>;
231
export const WebhookPayloadV3Schema = z.object({
232
id: z.string(),
233
timestamp: z.string(),
234
- type: z.literal('composio.trigger.message'),
235
- metadata: z.object({
236
- log_id: z.string(),
237
- trigger_slug: z.string(),
238
- trigger_id: z.string(),
239
- connected_account_id: z.string(),
240
- auth_config_id: z.string(),
241
- user_id: z.string(),
234
+ type: z.string().refine(val => val.startsWith('composio.'), {
235
+ message: "V3 event type must start with 'composio.'",
236
}),
237
+ metadata: z
238
+ .object({
239
+ log_id: z.string(),
240
+ trigger_slug: z.string(),
241
+ trigger_id: z.string(),
242
+ connected_account_id: z.string(),
243
+ auth_config_id: z.string(),
244
+ user_id: z.string(),
245
+ })
246
+ .passthrough(),
247
data: z.record(z.unknown()),
248
});
249
export type WebhookPayloadV3 = z.infer<typeof WebhookPayloadV3Schema>;
ts/packages/core/test/models/verifyWebhook.test.ts
+32
@@ -160,6 +160,38 @@ describe('Triggers.verifyWebhook', () => {
160
status: 'ACTIVE',
161
});
162
});
163
+
164
+ it('should detect V3 payload with non-trigger event type (e.g., connected_account.expired)', async () => {
165
+ // This test verifies the fix for PLEN-1397: V3 payloads with event types other than
166
+ // 'composio.trigger.message' should still be detected as V3, not fall back to V2
167
+ const payload = {
168
+ id: 'msg_abc123',
169
+ timestamp: new Date().toISOString(),
170
+ type: 'composio.connected_account.expired', // Not 'composio.trigger.message'
171
+ metadata: {
172
+ log_id: 'log-123',
173
+ trigger_slug: '',
174
+ trigger_id: '',
175
+ connected_account_id: 'conn-123',
176
+ auth_config_id: 'auth-123',
177
+ user_id: 'user-456',
178
+ },
179
+ data: { reason: 'token_expired' },
180
+ };
181
+ const payloadStr = JSON.stringify(payload);
182
+ const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
183
+
184
+ const result = await triggers.verifyWebhook({
185
+ payload: payloadStr,
186
+ signature,
187
+ secret: testSecret,
188
+ id: testWebhookId,
189
+ timestamp: testTimestamp,
190
+ });
191
+
192
+ expect(result.version).toBe(WebhookVersions.V3); // Should be V3, not V2
193
+ expect(result.rawPayload).toEqual(payload);
194
+ });
195
});
196
197
describe('successful verification with V2 payload', () => {