Skip to content

Commit

Permalink
feat: make a request when a question is posted
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaisdavid committed Jun 3, 2024
1 parent 9d0045c commit e69c53e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,38 @@ export const notifyNewHowTo = functions
},
)
})

export const notifyNewQuestion = functions
.runWith({ memory: '512MB' })
.firestore.document('questions_rev20230926/{id}')
.onCreate((snapshot) => {
const info = snapshot.data()
console.log(info)

const username = info._createdBy
const title = info.title
const slug = info.slug

const moderation = info.moderation

if (moderation === IModerationStatus.AWAITING_MODERATION) {
return
}

request.post(
SLACK_WEBHOOK_URL,
{
json: {
text: `❓ ${username} has a new question: ${title}\n Help them out and answer here: ${SITE_URL}/questions/${slug}`,
},
},
(error, response) => {
if (error) {
console.error(error)
return
} else {
return response
}
},
)
})
1 change: 1 addition & 0 deletions functions/src/Integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as IntegrationsPatreon from './patreon'

exports.notifyNewPin = IntegrationsSlack.notifyNewPin
exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo
exports.notifyNewQuestion = IntegrationsSlack.notifyNewQuestion
exports.notifyPinAccepted = IntegrationsDiscord.notifyPinAccepted
exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted
exports.patreonAuth = IntegrationsPatreon.patreonAuth

0 comments on commit e69c53e

Please sign in to comment.