0

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

1 Answer 1

1

This line of code looks like a problem:

console.log('We have a notification to send to token: ’ , receiver_token);

Your beginning quote is a single quote (apostrophe), but your end quote is a different quote mark. Look at them very carefully. Make the second one match the first one.

Sign up to request clarification or add additional context in comments.

1 Comment

That was the case. I am using TextEdit in Macbook, which did not catch the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.