diff --git a/functions/src/Integrations/firebase-discord.ts b/functions/src/Integrations/firebase-discord.ts index 40d6a029d8..9639adfff8 100644 --- a/functions/src/Integrations/firebase-discord.ts +++ b/functions/src/Integrations/firebase-discord.ts @@ -54,6 +54,31 @@ export const notifyHowToAccepted = functions .catch(handleErr) }) +export const notifyAcceptedQuestion = functions + .runWith({ memory: '512MB' }) + .firestore.document('questions_rev20230926/{id}') + // currently, questions are immediately posted with no review. + // if that changes, this code will need to be updated. + .onCreate(async (snapshot) => { + const info = snapshot.data() + console.log(info) + + const username = info._createdBy + const title = info.title + const slug = info.slug + + try { + const response = await axios.post(DISCORD_WEBHOOK_URL, { + json: { + text: `❓ ${username} has a new question: ${title}\n Help them out and answer here: ${SITE_URL}/questions/${slug}`, + }, + }) + handleResponse(response) + } catch (error) { + handleErr(error) + } + }) + const handleResponse = (res: AxiosResponse) => { console.log('post success') return res diff --git a/functions/src/Integrations/index.ts b/functions/src/Integrations/index.ts index 2cbf2a710e..6cb475ffa6 100644 --- a/functions/src/Integrations/index.ts +++ b/functions/src/Integrations/index.ts @@ -3,7 +3,11 @@ import * as IntegrationsDiscord from './firebase-discord' import * as IntegrationsPatreon from './patreon' exports.notifyNewPin = IntegrationsSlack.notifyNewPin -exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo exports.notifyPinAccepted = IntegrationsDiscord.notifyPinAccepted + +exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted + +exports.notifyAcceptedQuestion = IntegrationsDiscord.notifyAcceptedQuestion + exports.patreonAuth = IntegrationsPatreon.patreonAuth