Skip to content

Commit

Permalink
added function to send message when new waitlist member sign
Browse files Browse the repository at this point in the history
  • Loading branch information
danicuki committed Sep 26, 2023
1 parent f11f38a commit 4ece294
Show file tree
Hide file tree
Showing 5 changed files with 6,493 additions and 5 deletions.
18 changes: 13 additions & 5 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"hosting": {
"public": "./",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log"]
}
],
"emulators": {
"database": {
"port": 9000
}
}
}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
36 changes: 36 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { onRequest } = require("firebase-functions/v2/https")
const logger = require("firebase-functions/logger")

const functions = require("firebase-functions")
const admin = require("firebase-admin")

const axios = require("axios")

if (process.env.FUNCTIONS_EMULATOR) {
admin.initializeApp({
databaseURL: "http://localhost:9000", // Use the emulator URL when testing locally
})
} else {
admin.initializeApp()
}

function sendDiscordMessage(content, avatar_url) {
const url =
"https://discord.com/api/webhooks/979143707880222761/dpn2gt9IhEDRzkwICdCHDxwglww7zSjBi4wSlw-4F2t6Tpv8tCECyt8YtIf7py6I31oH"
return axios.post(url, { content, avatar_url })
}

exports.captureNewNode = functions.database
.ref("/{nodeType}/{nodeId}")
.onCreate((snapshot, context) => {
const email = snapshot.val()
const nodeType = context.params.nodeType // This will capture 'business', 'community_leader', or 'professional'
const nodeId = context.params.nodeId // This will capture the ID of the newly added record

const msg = `New record added to ${nodeType} with ID ${nodeId} and email: ${email}`
console.log(msg)

return sendDiscordMessage(msg, "https://i.imgur.com/OyQ6ued.png").then((r) => {
return null
})
})
Loading

0 comments on commit 4ece294

Please sign in to comment.