feat: make a webhook for when a question is accepted

This commit is contained in:
David Germain
2024-06-03 19:59:10 +02:00
parent b5ef8c0d56
commit 5f716b9fba
2 changed files with 36 additions and 0 deletions

View File

@@ -64,3 +64,38 @@ export const notifyNewHowTo = functions
},
)
})
export const notifyAcceptedQuestion = 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.ACCEPTED) {
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
}
},
)
})

View File

@@ -4,6 +4,7 @@ import * as IntegrationsPatreon from './patreon'
exports.notifyNewPin = IntegrationsSlack.notifyNewPin
exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo
exports.notifyAcceptedQuestion = IntegrationsSlack.notifyAcceptedQuestion
exports.notifyPinAccepted = IntegrationsDiscord.notifyPinAccepted
exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted
exports.patreonAuth = IntegrationsPatreon.patreonAuth