是否有原因为什么通知脚本突然开始抛出Slack API代码400:无效的块?

发布于 2025-02-09 05:52:46 字数 2882 浏览 2 评论 0原文

我有这个脚本工作了3个月以上,没有问题,但是上周它开始抛出这一点:

Error   
Exception: Request failed for https://hooks.slack.com returned code 400. Truncated server response: invalid_blocks (use muteHttpExceptions option to examine full response)

我认为这是脚本的相关部分。

  for (let i = 0; i in vistasVencimiento; i++){
    if (vistasVencimiento[i][0] instanceof Date == true){
      let differenceInMs = dateToday - vistasVencimiento[i][0];
      let differenceInDaysRaw = differenceInMs / (1000 * 60 * 60 * 24);

      if(differenceInDaysRaw >= 0 && statusColumn[i] !== "Pendiente_de_despacho"){
        //agregar a array de vencidos
        result.push(sumariantesVistas[i], causasCaratulas[i], '\n');
      }
    }
  };
  console.log(result);
  if (result === undefined || result.length === 0 ){
    let payload ={
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": ":bell: *Cuales Vistas estan vencidas?* :bell:"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text":"Aparentemente, ninguna"
            }
        },
    ]
  }
      let headers = {
      'Content-type': 'application/json'
    };
    let options = {
      headers : headers,
      method: 'POST',
      payload: JSON.stringify(payload)
    };
  UrlFetchApp.fetch(url, options);

  }else{
    let result_string = result.join('\n');
    let payload ={
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": ":bell: *Cuales Vistas estan vencidas?* :bell:"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text":"Estas: "
            }
        },
        { 
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": result_string
            }
        },      
    ]
  }
      let headers = {
      'Content-type': 'application/json'
    };
    let options = {
      muteHttpExceptions: false,
      headers : headers,
      method: 'POST',
      payload: JSON.stringify(payload)
    };
  UrlFetchApp.fetch(url, options);

  };

现在,我知道它与“ text”:result_string有关将弦到Slack Workplace频道,这基本上不知道为什么它会突然出现这样的

编辑: 这里有一些非常奇怪的事情发生,首先要进行cousascaratulas [i] .replace(/“/g,”)没有修复任何东西,其次,Cousascaratulas内部有两个列,如果我只加载一列(无关紧要) )脚本起作用,我甚至尝试将数组分为两个列表列表,在这种情况下,它仍然抛出 错误。 因此,错误发生在尝试将这两列列出到Slack API之间的某个地方吗?关于这里发生的事情

编辑2: 数据是这样的。问题似乎是,每当我尝试同时发送案例号和案例名称时,我都会遇到错误,但是,这似乎取决于某种神秘的符号IDK如何识别它是否甚至是符号。

I've had this script working for over 3 months with no issues, however, last week it started throwing out this:

Error   
Exception: Request failed for https://hooks.slack.com returned code 400. Truncated server response: invalid_blocks (use muteHttpExceptions option to examine full response)

Here's the relevant part of the script i think.

  for (let i = 0; i in vistasVencimiento; i++){
    if (vistasVencimiento[i][0] instanceof Date == true){
      let differenceInMs = dateToday - vistasVencimiento[i][0];
      let differenceInDaysRaw = differenceInMs / (1000 * 60 * 60 * 24);

      if(differenceInDaysRaw >= 0 && statusColumn[i] !== "Pendiente_de_despacho"){
        //agregar a array de vencidos
        result.push(sumariantesVistas[i], causasCaratulas[i], '\n');
      }
    }
  };
  console.log(result);
  if (result === undefined || result.length === 0 ){
    let payload ={
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": ":bell: *Cuales Vistas estan vencidas?* :bell:"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text":"Aparentemente, ninguna"
            }
        },
    ]
  }
      let headers = {
      'Content-type': 'application/json'
    };
    let options = {
      headers : headers,
      method: 'POST',
      payload: JSON.stringify(payload)
    };
  UrlFetchApp.fetch(url, options);

  }else{
    let result_string = result.join('\n');
    let payload ={
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": ":bell: *Cuales Vistas estan vencidas?* :bell:"
            }
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text":"Estas: "
            }
        },
        { 
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": result_string
            }
        },      
    ]
  }
      let headers = {
      'Content-type': 'application/json'
    };
    let options = {
      muteHttpExceptions: false,
      headers : headers,
      method: 'POST',
      payload: JSON.stringify(payload)
    };
  UrlFetchApp.fetch(url, options);

  };

Now, I know its related to "text": result_string because ive tried replacing that with something like "text": "test" and it works, but the whole point of the notifications is to send that formatted string to a slack workplace channel, and thats where ive basically no clue on why it would start failing out of a sudden like that

edit:
Theres something genuinely very weird going on here, first of all going causasCaratulas[i].replace(/"/g, "'") doesnt fix anything, second, causasCaratulas has two columns inside, if i load only one column (doesnt matter which) the script works, ive even tried splitting the array into two sorta-lists, in that case, it still throws out the error.
So the error happens somewhere between trying to send out those two columns to the slack api at the same time? im clueless as to whats happening here

edit 2:
the data is structured something like this. the problem seems to be that whenever i try sending both Case Number and Case Name at the same time i get an error, however, this seems to be dependant on some kind of mystery symbol idk how to identify, if it even is a symbol.enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2025-02-16 05:52:46

也许您的文本数据包含&<?尝试以下操作:

    let result_string = result
      .join('\n')
      .replace(/&/g, '&')
      .replace(/</g, '<')
      .replace(/>/g, '>');

请参阅在Slack Api参考中逃脱的文本

您还应该在数据中搜索可能会在工作中抛出扳手的标记符号。

Perhaps your text data contains &<>? Try this:

    let result_string = result
      .join('\n')
      .replace(/&/g, '&')
      .replace(/</g, '<')
      .replace(/>/g, '>');

See Escaping text at Slack API reference.

You should also search your data for markdown symbols that could throw a spanner in the works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文