Skip to content

Commit

Permalink
Fix Groups-io webhooks (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
sausage-todd authored Oct 9, 2023
1 parent beed131 commit 7a66088
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions services/apps/webhook_api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ setImmediate(async () => {

const dbConnection = await getDbConnection(DB_CONFIG(), 3)

app.use((req, res, next) => {
// Groups.io doesn't send a content-type header,
// so request body parsing is just skipped
// But we fix it
if (!req.headers['content-type']) {
req.headers['content-type'] = 'application/json'
}
next()
})

app.use(cors({ origin: true }))
app.use(express.json({ limit: '5mb' }))
app.use(express.urlencoded({ extended: true, limit: '5mb' }))
Expand Down
7 changes: 4 additions & 3 deletions services/apps/webhook_api/src/routes/groupsio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export const installGroupsIoRoutes = async (app: express.Express) => {
const data = req.body

// TODO: Validate signature - need to get secret from groups io for Linux
const groupName = data?.group?.name

if (!data?.group?.name) {
if (!groupName) {
throw new Error400BadRequest('Missing group name!')
}

const repo = new WebhooksRepository(req.dbStore, req.log)

const integration = await repo.findGroupsIoIntegrationByGroupName(data.group.name)
const integration = await repo.findGroupsIoIntegrationByGroupName(groupName)

if (integration) {
req.log.info({ integrationId: integration.id }, 'Incoming Groups.io Webhook!')
Expand All @@ -47,7 +48,7 @@ export const installGroupsIoRoutes = async (app: express.Express) => {

res.sendStatus(204)
} else {
req.log.error({ event }, 'No integration found for incoming Groups.io Webhook!')
req.log.error({ event, groupName }, 'No integration found for incoming Groups.io Webhook!')
res.status(200).send({
message: 'No integration found for incoming Groups.io Webhook!',
})
Expand Down

0 comments on commit 7a66088

Please sign in to comment.