Skip to content

Instantly share code, notes, and snippets.

@BernardGatt
Created November 8, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BernardGatt/6f1bce1cc17e81b354a811fb3afebb76 to your computer and use it in GitHub Desktop.
Save BernardGatt/6f1bce1cc17e81b354a811fb3afebb76 to your computer and use it in GitHub Desktop.
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