Skip to content

How to use template literal in Firebase Cloud Function condition

Is it possible to use template literal in message condition of Firebase Cloud Function?

I tried the following but it is not working.

topic1 = `${}`
topic2 = `${}`
var condition = "topic1 in topics || topic2 in topics";

var message = {
  notification: {
    title: 'My object',
    body: 'My object.'
  condition: condition


I changed to this but it is still not working:

      topic = "_full";
      topic1 = `${myObj.field1}` + topic;
      topic2 = (`${myObj.field2.field1}_${myObj.field2.field2}` + topic)
        .split(" ")
      topic3 = `${myObj.field3.field1}` + topic;
      topic4 = `${myObj.field4.field1}` + topic;

      condition = `${topic1} in topics || ${topic2} in topics || ${topic3} in topics || ${topic4} in topics`;

I get “Error: Invalid condition expression provided.”



Don’t forget to add single quotes around topics:

var condition = `'${topic1}' in topics || '${topic2}' in topics`;