( message: Message<WebhookDeliveryMessage>, env: Env )
| 251 | kiloclawInstanceId: triggerConfig.kiloclawInstanceId, |
| 252 | conversationId: result.conversationId, |
| 253 | conversationCreated: result.conversationCreated, |
| 254 | messageId: result.messageId, |
| 255 | }); |
| 256 | |
| 257 | await withDORetry( |
| 258 | () => stub, |
| 259 | doStub => |
| 260 | doStub.updateRequest(webhook.requestId, { |
| 261 | process_status: 'success', |
| 262 | completed_at: new Date().toISOString(), |
| 263 | }), |
| 264 | 'updateRequest' |
| 265 | ); |
| 266 | } |
| 267 | |
| 268 | async function processWebhookMessage( |
| 269 | message: Message<WebhookDeliveryMessage>, |
| 270 | env: Env |
| 271 | ): Promise<void> { |
| 272 | const webhook = message.body; |
| 273 | let sessionCreated = false; |
| 274 | let canRetryInitiate = false; |
| 275 | let cloudAgentSessionId: string | null = null; |
| 276 | let isExistingChatDelivery = false; |
| 277 | |
| 278 | logger.info('Processing webhook delivery', { |
| 279 | namespace: webhook.namespace, |
| 280 | triggerId: webhook.triggerId, |
| 281 | requestId: webhook.requestId, |
| 282 | }); |
| 283 | |
| 284 | try { |
| 285 | const doKey = `${webhook.namespace}/${webhook.triggerId}`; |
| 286 | const doId = env.TRIGGER_DO.idFromName(doKey); |
| 287 | const stub = env.TRIGGER_DO.get(doId); |
| 288 | |
| 289 | const [request, triggerConfig] = await Promise.all([ |
| 290 | withDORetry( |
| 291 | () => stub, |
| 292 | doStub => doStub.getRequest(webhook.requestId), |
| 293 | 'getRequest' |
| 294 | ), |
| 295 | withDORetry( |
| 296 | () => stub, |
| 297 | async (doStub): Promise<TriggerConfig | null> => await doStub.getConfig(), |
| 298 | 'getConfig' |
| 299 | ), |
| 300 | ]); |
| 301 | |
| 302 | if (!request) { |
| 303 | logger.error('Request evicted before processing - data loss', { |
| 304 | requestId: webhook.requestId, |
| 305 | namespace: webhook.namespace, |
| 306 | triggerId: webhook.triggerId, |
| 307 | error: 'REQUEST_EVICTED', |
| 308 | }); |
| 309 | message.ack(); |
| 310 | return; |
no test coverage detected