-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-webhook.ts
More file actions
83 lines (69 loc) · 2.34 KB
/
Copy pathcustom-webhook.ts
File metadata and controls
83 lines (69 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Custom Webhook Integration
*
* This plugin sends OpenCode events to any custom webhook endpoint.
*
* Setup Instructions:
* 1. Copy this file to ~/.config/opencode/plugin/custom-webhook.ts
* 2. Update the WEBHOOK_URL below with your webhook endpoint
* 3. Customize the events, transformPayload, or other options as needed
* 4. Restart OpenCode
*/
import type { Plugin } from '@opencode-ai/plugin';
import { createWebhookPlugin } from 'opencode-webhooks';
// ============================================================================
// Configuration
// ============================================================================
const WEBHOOK_URL = 'https://your-webhook-endpoint.com/api/events';
// ============================================================================
// Plugin Setup
// ============================================================================
// Export the plugin with explicit type annotation for OpenCode
const CustomWebhookPlugin: Plugin = createWebhookPlugin({
webhooks: [
{
url: WEBHOOK_URL,
// Which events to send
events: [
'session.created',
'session.idle',
'session.deleted',
'session.error',
'session.resumed',
'message.updated',
'message.part.updated',
],
// Optional: Transform the payload before sending
transformPayload: (payload) => {
// Extract message content if available
const messageContent = payload.content || payload.text || payload.message;
return {
...payload,
// Add a cleaned/extracted message field
messageContent: messageContent || null,
// Add custom metadata
customField: 'custom value',
};
},
// Optional: Filter events
// shouldSend: (payload) => {
// // Only send error events
// return payload.eventType === 'session.error';
// },
// Optional: Custom headers
headers: {
'Content-Type': 'application/json',
// 'Authorization': 'Bearer YOUR_TOKEN',
},
// Retry configuration
retry: {
maxAttempts: 3,
delayMs: 1000,
},
timeoutMs: 5000,
},
],
// Enable debug logging (set to false in production)
debug: false,
});
export default CustomWebhookPlugin;