I am trying to send one to one notification from android device using Firebase Cloud Messaging service and code in Fireabse CLI. But I am failing to deploy the code due to parsing error, which I cannot figure out.
My idea is as follows: For security reasons, I understand, I need to use Firebase Cloud functions to send notification. From my android code I will be writing the target device's token, message body and topic in Firebase database. As soon as the write event occurs, the Firease function would get deployed to send the notification. Here is my Firebase code
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notification/{receiver_token}/{message_topic}/{message_body}’).onWrite((data, context) =>
{
const receiver_token = context.params.receiver_token;
const message_topic = context.params.message_topic;
const message_body = context.params.message_body;
console.log('We have a notification to send to token: ’ , receiver_token);
const payload =
{
notification:
{
title: message_topic,
body: message_body,
icon: "default"
}
};
return admin.messaging().sendToDevice(receiver_token, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
When I am trying to deploy this function in Firebase, I am getting the following error:
error Parsing error: Unterminated string constant Error: functions predeploy error: Command terminated with non-zero exit code1
I can provide the complete error log if needed