i want to send dm to several people in slack using google script. i have all their webhooks. but i dont know the code to send it using several webhooks.
message error : Exception: Invalid argument: [https://hooks.slack.com/services/XXXXX,https://hooks.slack.com/services/YYYYY]
var ss =SpreadsheetApp.getActiveSpreadsheet();
var ji = ss.getSheetByName('Mailer');
var url = "[https://hooks.slack.com/services/XXXXX,https://hooks.slack.com/services/YYYYY]";
var ji_ticket =ji.getRange(3,3,ji.getLastRow()-2,1).getValues();
var linkticket = ji.getRange(3,4,ji.getLastRow()-2,1).getValues();
var total_ticket = ji.getRange("C2").getValue();
var status = ji.getRange("C1").getValue();
var payload =
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bell: *Pending Ticket* :bell:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text":
"Hi Leaders,\n\n"
"There are " total_ticket " tickets pending. Kindly click this tickets: " linkticket
//"\n\n\nThankyou"
}
}
]
};
Logger.log(payload)
var params = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
if(status=='Yes'){
return UrlFetchApp.fetch(url,params);
}
}```
CodePudding user response:
UrlFetchApp.fetch(url,params)
can only fetch a single URL per call, so you can try to call the API for each webhook.
var url1 = "https://hooks.slack.com/services/XXXXX";
var url2 = "https://hooks.slack.com/services/YYYYY";
...
UrlFetchApp.fetch(url1,params);
UrlFetchApp.fetch(url2,params);
Reference: