Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add questions webhook #3619

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions functions/src/Integrations/firebase-discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion functions/src/Integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading