Created
January 15, 2021 07:31
-
-
Save andreasvirkus/b52248f7c2c86f4fd8466edb99c0ce24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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