错误:SyntaxError:意外的令牌C在JSON中的位置33在规则附件,而在谷歌firebase做



我正在使用GCP和slack开发firebase。当这个集成我得到这个

Error: SyntaxError: JSON中在rule attachments位置33的意外token C.

我已经试了很多次,但不幸的是我找不到解决它的方法。

实际错误仅在代码中..

任何人都可以帮我解决这个问题!!

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 => {
querySnapshot.docChanges().forEach(change => {
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) => {
const data = message.json;
return Promise.all(
rules.map(rule => {
if (evalTest(data, rule.test)) {
return sendSlack(data, rule);
}
return Promise.resolve();
})
);
});

上面是我的代码1。下面是json文件 的另一个代码

{
"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
}

上面的代码中没有错误。防火控制台上的数据应该是清晰的。

最新更新