我试图设置两个变量“ TOTAL_GHE_ISSUES”“ GHE_ISSUE_NUMBERS”,然后将它们插入到https://slack.dev/node-slack-sdk/webhook之后的松弛Webhook的json有效负载中。我对js / nodejs完全没有经验,所以请理解我是否犯了一个简单的错误我尝试在.js脚本顶部设置变量,并尝试转义/取消转义值,但是遇到了麻烦const IncomingWebhook = require('@slack/webhook').IncomingWebhook;const url = process.env.SLACK_WEBHOOK_URL;const webhook = new IncomingWebhook(url);var x = "10"const TOTAL_GHE_ISSUES = "10"const GHE_ISSUE_NUMBERS = "90"// Send the notificationif (x == "10")(async () => { await webhook.send({ text: "*Daily Overdue Nessus Vulnerability Alert*", attachments: [{color: "#FF0000", blocks: [{type: "section",text: {type: "mrkdwn",text: "@here *TOTAL_GHE_ISSUES* Overdue Nessus Vulnerability issues reported \nOverdue Nessus Vulnerability GHE Issue Numbers: *GHE_ISSUE_NUMBERS*"}}]}] });})();else {console.log("What's up");}我希望webhook返回TOTAL_GHE_ISSUES和GHE_ISSUE_NUMBERS的10和90,但它返回的是文字字符串编辑:我使用了下面发布的字符串连接,它达到了我的目的,并使我的有效负载更加模块化,非常感谢您的所有帮助text: "@here *" + TOTAL_GHE_ISSUES + "* Overdue Nessus Vulnerability issues reported \nOverdue Nessus Vulnerability GHE Issue Numbers: *" + GHE_ISSUE_NUMBERS + "*"
2 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
您可以简单地使用``(模板文字)
text: `@here *${TOTAL_GHE_ISSUES}* Overdue Nessus Vulnerability issues reported \nOverdue Nessus Vulnerability GHE Issue Numbers: *${GHE_ISSUE_NUMBERS}*`
或者您也可以使用字符串缩写
text: "@here *" + TOTAL_GHE_ISSUES + "* Overdue Nessus Vulnerability issues reported \nOverdue Nessus Vulnerability GHE Issue Numbers: *" + GHE_ISSUE_NUMBERS + "*"
添加回答
举报
0/150
提交
取消