MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / processWebhookMessage

Function processWebhookMessage

services/webhook-agent-ingest/src/queue-consumer.ts:253–656  ·  view source on GitHub ↗
(
  message: Message<WebhookDeliveryMessage>,
  env: Env
)

Source from the content-addressed store, hash-verified

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
268async 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;

Callers 1

Calls 15

withDORetryFunction · 0.90
renderPromptTemplateFunction · 0.90
deriveCallbackTokenFunction · 0.90
classifyInitiateResponseFunction · 0.90
failRequestFunction · 0.85
getOrMintTokenFunction · 0.85
getRequestMethod · 0.80
updateRequestMethod · 0.80
infoMethod · 0.65
getMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected