## 今天我們要使用Firebase functions 推送 FCM 給昨天我們寫好的 APP
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
/////is ok
exports.helloFCM = functions.region('asia-northeast1').https.onRequest(async (request, response) => {
console.log('A new user signed in for the first time.');
const fullName = 'Anonymous';
const Ipad_token = "cTBvQaDOt1A:APAXXXXXXXX5U6K1zhNfw4FkKJ";
var registrationToken = 'YOUR_REGISTRATION_TOKEN';
var topic = 'highScores';
var message = {
data: {
score: '850',
time: '2:45'
},
notification: {
title: "FCM D 加辣",
body: "FCM D 加辣",
},
token: Ipad_token
};
await admin.messaging().send(message).then((response) => {
console.log('Successfully sent message:', response);
return null;
})
admin.messaging().send(message).then((response) => {
console.log('Successfully sent message:', response);
return null;
})
.catch((error) => {
console.log('Error sending message:', error);
});