Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created January 15, 2021 07:31
Show Gist options
  • Save andreasvirkus/b52248f7c2c86f4fd8466edb99c0ce24 to your computer and use it in GitHub Desktop.
Save andreasvirkus/b52248f7c2c86f4fd8466edb99c0ce24 to your computer and use it in GitHub Desktop.
function buildReport() {
const ss = SpreadsheetApp.getActive();
const data = ss.getSheetByName('SUMMARY').getRange("A1").getValues();
const payload = buildAlert(data);
Logger.log(data);
sendAlert(payload);
}
function buildAlert(data) {
const mrr = data[0][0];
const payload = {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bell: *Daily MRR Report* :bell:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Our NET MRR for this month is " + mrr
}
}
]
};
return payload;
}
function sendAlert(payload) {
const webhook = "https://hooks.slack.com/services/<your-webhook-goes-here>";
const options = {
"method": "post",
"contentType": "application/json",
"muteHttpExceptions": true,
"payload": JSON.stringify(payload)
};
try {
UrlFetchApp.fetch(webhook, options);
} catch(e) {
Logger.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment