Skip to content

Instantly share code, notes, and snippets.

@MarcosSarges
Created May 22, 2022 12:55
Show Gist options
  • Save MarcosSarges/3e4806161ab74bf0e4e4150ab8c7b226 to your computer and use it in GitHub Desktop.
Save MarcosSarges/3e4806161ab74bf0e4e4150ab8c7b226 to your computer and use it in GitHub Desktop.
Send Cloud Message Lagacy
const { default: axios } = require("axios");
require("dotenv").config();
const FCM_TOKEN = "";
(async () => {
try {
const body = {
registration_ids: [FCM_TOKEN],
data: {
score: "5x1",
time: "15:10",
},
notification: {
title: "teste",
body: "asf",
subtitle: "asg",
},
};
const http = axios.create({ baseURL: "https://fcm.googleapis.com/fcm" });
const headers = {};
headers["Content-Type"] = "application/json";
headers["Authorization"] = `key=${process.env.AUTH_KEY_GOOGLE}`;
http.defaults.headers.post = headers;
const { data: res } = await http.post("/send", body);
console.log(res);
} catch (error) {
console.log(error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment