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.