Created
June 12, 2020 12:09
-
-
Save michimani/8a9234cf2345b31bbedc9b9f58c77fac to your computer and use it in GitHub Desktop.
Sample Google Apps Script that set Slack status emoji and message.
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
const slackUserId = 'XXXXXXXX'; // your user ID | |
const slackApiToken = 'xoxp-******-*******-******'; // your API token | |
const slackSetStatusUrl = 'https://slack.com/api/users.profile.set'; | |
function changeSlackStatus(emoji, message) { | |
const headers = { | |
'Authorization': 'Bearer ' + slackApiToken, | |
'X-Slack-User': slackUserId, | |
'COntent-Type': 'application/json; charset=utf-8' | |
}; | |
const payload = { | |
'profile': { | |
'status_emoji': emoji, | |
'status_text': message | |
} | |
}; | |
const options = { | |
'method': 'post', | |
'headers': headers, | |
'payload': JSON.stringify(payload) | |
}; | |
const res = UrlFetchApp.fetch(slackSetStatusUrl, options); | |
const resJson = JSON.parse(res.getContentText()); | |
console.log(JSON.stringify(resJson, false, 2)); | |
} | |
function myFunction() { | |
changeSlackStatus(':ghost:', 'by Google App Script.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment