mirror of https://github.com/buster-so/buster.git
Merge branch 'staging' into big-nate/bus-1355-make-it-so-regular-users-can-invite-others
This commit is contained in:
commit
00c7a3d13e
|
@ -16,9 +16,37 @@ const app = new Hono()
|
||||||
.delete('/integration', requireAuth, (c) => slackHandler.removeIntegration(c))
|
.delete('/integration', requireAuth, (c) => slackHandler.removeIntegration(c))
|
||||||
// Events endpoint (no auth required for Slack webhooks)
|
// Events endpoint (no auth required for Slack webhooks)
|
||||||
.post('/events', async (c) => {
|
.post('/events', async (c) => {
|
||||||
const body = await c.req.json();
|
try {
|
||||||
const response = await eventsHandler(body);
|
// Slack sends different content types for different events
|
||||||
return c.json(response);
|
// For URL verification, it's application/x-www-form-urlencoded
|
||||||
|
// For actual events, it's application/json
|
||||||
|
const contentType = c.req.header('content-type');
|
||||||
|
|
||||||
|
if (contentType?.includes('application/x-www-form-urlencoded')) {
|
||||||
|
// Handle URL verification challenge
|
||||||
|
const formData = await c.req.parseBody();
|
||||||
|
if (formData.challenge) {
|
||||||
|
return c.text(formData.challenge as string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For JSON payloads, try to parse but don't fail
|
||||||
|
let body = null;
|
||||||
|
if (contentType?.includes('application/json')) {
|
||||||
|
try {
|
||||||
|
body = await c.req.json();
|
||||||
|
} catch {
|
||||||
|
// If JSON parsing fails, just continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await eventsHandler(body);
|
||||||
|
return c.json(response);
|
||||||
|
} catch (error) {
|
||||||
|
// Log the error but always return 200 OK for Slack
|
||||||
|
console.error('Error processing Slack event:', error);
|
||||||
|
return c.json({ success: true });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// Error handling
|
// Error handling
|
||||||
.onError((e, c) => {
|
.onError((e, c) => {
|
||||||
|
|
Loading…
Reference in New Issue