Created
November 8, 2021 18:19
-
-
Save BernardGatt/6f1bce1cc17e81b354a811fb3afebb76 to your computer and use it in GitHub Desktop.
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
const functions = require("firebase-functions"); | |
const axios = require("axios"); | |
exports.sendWelcomeMessage = functions.firestore | |
.document("users/{userId}") | |
.onCreate(async (user, context) => { | |
const userData = user.data(); | |
await sendGistMessage("welcome", "bottom", context.params.userId, userData); | |
}); | |
const sendGistMessage = async (messageId, position, userId, properties) => { | |
const queue = axios.create({ | |
baseURL: "https://queue.api.gist.build", | |
headers: { | |
"Content-Type": "application/json", | |
"X-Bourbon-Organization-Id": "organization-id", | |
"X-Gist-Service-Key": "service-key", | |
}, | |
}); | |
properties.gist = { | |
"position": position, | |
}; | |
const message = { | |
"messageId": messageId, | |
"userToken": userId, | |
"properties": properties, | |
"priority": 1, | |
}; | |
await queue.post("/api/v1/messages", message); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment