(chat: Chat, slackAdapter: SlackAdapter)
| 93 | * the Slack adapter. |
| 94 | */ |
| 95 | export 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 | } |
no test coverage detected