* Send webhook notification for an action request. * Fire-and-forget: doesn't wait for response, logs errors but doesn't throw.
(actionRequest: ActionRequest)
| 134 | * Fire-and-forget: doesn't wait for response, logs errors but doesn't throw. |
| 135 | */ |
| 136 | function sendWebhooks(actionRequest: ActionRequest): void { |
| 137 | const webhookUrls = getWebhookUrls(); |
| 138 | |
| 139 | if (webhookUrls.length === 0) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | const payload = JSON.stringify(actionRequest); |
| 144 | |
| 145 | for (const url of webhookUrls) { |
| 146 | // Fire and forget - use .then().catch() instead of await |
| 147 | fetch(url, { |
| 148 | method: "POST", |
| 149 | headers: { |
| 150 | "Content-Type": "application/json", |
| 151 | "User-Agent": "Agentation-Webhook/1.0", |
| 152 | }, |
| 153 | body: payload, |
| 154 | }) |
| 155 | .then((res) => { |
| 156 | log( |
| 157 | `[Webhook] POST ${url} -> ${res.status} ${res.statusText}` |
| 158 | ); |
| 159 | }) |
| 160 | .catch((err) => { |
| 161 | console.error(`[Webhook] POST ${url} failed:`, (err as Error).message); |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | log( |
| 166 | `[Webhook] Fired ${webhookUrls.length} webhook(s) for session ${actionRequest.sessionId}` |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | // ----------------------------------------------------------------------------- |
| 171 | // Request Helpers |
no test coverage detected
searching dependent graphs…