-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added function to send message when new waitlist member sign
- Loading branch information
Showing
5 changed files
with
6,493 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
Oops, something went wrong.