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

Function createSlackWebhookHandler

apps/web/src/lib/bot/platforms/slack-webhook.ts:95–128  ·  view source on GitHub ↗
(chat: Chat, slackAdapter: SlackAdapter)

Source from the content-addressed store, hash-verified

93 * the Slack adapter.
94 */
95export function createSlackWebhookHandler(chat: Chat, slackAdapter: SlackAdapter) {
96 return async (request: Request, options?: WebhookOptions): Promise<Response> => {
97 const body = await request.text();
98
99 if (!verifySlackSignature(body, request)) {
100 return new Response('Invalid signature', { status: 401 });
101 }
102
103 await chat.initialize();
104
105 let payload: unknown;
106 try {
107 payload = JSON.parse(body);
108 } catch {
109 return slackAdapter.handleWebhook(cloneSlackRequest(request, body), options);
110 }
111
112 if (isSlackAppUninstalledPayload(payload)) {
113 try {
114 await handleSlackAppUninstalled(payload.team_id, chat, slackAdapter);
115 } catch (error) {
116 console.error('[Bot] Failed to handle Slack app_uninstalled event:', error);
117 captureException(error, {
118 tags: { component: 'kilo-bot', op: 'slack-app-uninstalled' },
119 extra: { teamId: payload.team_id },
120 });
121 }
122
123 return new Response('ok', { status: 200 });
124 }
125
126 return slackAdapter.handleWebhook(cloneSlackRequest(request, body), options);
127 };
128}

Callers 1

createKiloBotFunction · 0.90

Calls 7

verifySlackSignatureFunction · 0.85
cloneSlackRequestFunction · 0.85
textMethod · 0.65
errorMethod · 0.65
initializeMethod · 0.45

Tested by

no test coverage detected