title: Error: SyntaxError: Unexpected token C in JSON at position 33 in rule attachments while doing on google firebase
body: <p>I'm working on firebase with GCP and slack. while this integration i'm getting this</p>
  <p><strong>Error: SyntaxError: Unexpected token C in JSON at position 33 in rule attachments</strong> .</p>
  <p>I have tried lot , but unfortunately I couldn't find the solution of it.</p>
  <p>Actual Error is in the code only..</p>
  <p>Anybody can help me to sort out the issue!!</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const functions = require("firebase-functions");
  const admin = require("firebase-admin");
  const { WebClient } = require("@slack/web-api");
  
  admin.initializeApp(functions.config().firebase);
  
  const web = new WebClient(functions.config().gslack.api_token);
  const runtimeOpts = {
    timeoutSeconds: 30,
    memory: "256MB"
  };
  
  const rules = [];
  admin
    .firestore()
    .collection("gSlack")
    .where("disabled", "==", false)
    .onSnapshot(querySnapshot =&gt; {
      querySnapshot.docChanges().forEach(change =&gt; {
        const rule = {
          id: change.doc.id,
          ...change.doc.data()
        };
        if (change.type === "added") {
          rules.splice(change.newIndex, 0, rule);
        }
        if (change.type === "modified") {
          rules.splice(change.newIndex, 1, rule);
        }
        if (change.type === "removed") {
          rules.splice(change.oldIndex, 1);
        }
      });
    });
  
  function evalTest(data, test) {
    try {
      $ = data;
      return eval(`'use strict';(${test});`);
    } catch (err) {
      console.error(err, test);
      return false;
    }
  }
  
  function evalMessageText(data, message) {
    if (message) {
      try {
        $ = data;
        return eval(`'use strict';\`${message}\`;`);
      } catch (err) {
        console.error(err, message);
        return `Error: ${err} in rule message:\n ${message}`;
      }
    }
  }
  
  function evalMessageAttachments(data, attachments) {
    if (attachments) {
      try {
        $ = data;
        return JSON.parse(
          eval(`'use strict';\`${JSON.stringify(attachments)}\`;`)
        );
      } catch (err) {
        console.error(err, attachments);
        return [
          {
            title: "GSLACK ERROR",
            text: `Error: ${err} in rule attachments`
          }
        ];
      }
    }
  }
  
  function sendSlack(data, rule) {
    return web.chat.postMessage({
      as_user: true,
      channel: rule.channel,
      text: evalMessageText(data, rule.message),
      attachments: evalMessageAttachments(data, rule.attachments)
    });
  }
  
  exports.gSlack = functions
    .runWith(runtimeOpts)
    .pubsub.topic("gslack")
    .onPublish((message, context) =&gt; {
      const data = message.json;
      return Promise.all(
        rules.map(rule =&gt; {
          if (evalTest(data, rule.test)) {
            return sendSlack(data, rule);
          }
          return Promise.resolve();
        })
      );
    });</code></pre>
  </div>
  </div>
  </p>
  <p>Above is my code 1. below is an another code of json file</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    "name": "gslack",
    "description": "",
    "engines": {
      "node": "10"
    },
    "scripts": {
      "serve": "firebase serve --only functions",
      "shell": "firebase functions:shell",
      "start": "npm run shell",
      "deploy": "firebase deploy --only functions:gSlack",
      "logs": "firebase functions:log"
    },
    "dependencies": {
      "@slack/web-api": "^5.0.1",
      "firebase-admin": "~9.2.0",
      "firebase-functions": "^3.11.0"
    },
    "private": true
  }</code></pre>
  </div>
  </div>
  </p>