chore: move code to discord file

This commit is contained in:
David Germain
2024-06-14 19:09:40 +02:00
parent 3894a82267
commit b9d2bf0dec
3 changed files with 26 additions and 33 deletions

View File

@@ -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

View File

@@ -7,7 +7,6 @@ const SITE_URL = CONFIG.deployment.site_url
// e.g. https://dev.onearmy.world or https://community.preciousplastic.com
const SLACK_WEBHOOK_URL = CONFIG.integrations.slack_webhook
const DISCORD_WEBHOOK_URL = CONFIG.integrations.discord_webhook
export const notifyNewPin = functions
.runWith({ memory: '512MB' })
@@ -65,34 +64,3 @@ export const notifyNewHowTo = functions
},
)
})
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 change.
.onCreate((snapshot) => {
const info = snapshot.data()
console.log(info)
const username = info._createdBy
const title = info.title
const slug = info.slug
request.post(
DISCORD_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

@@ -8,6 +8,6 @@ exports.notifyPinAccepted = IntegrationsDiscord.notifyPinAccepted
exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo
exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted
exports.notifyAcceptedQuestion = IntegrationsSlack.notifyAcceptedQuestion
exports.notifyAcceptedQuestion = IntegrationsDiscord.notifyAcceptedQuestion
exports.patreonAuth = IntegrationsPatreon.patreonAuth