Skip to content

Instantly share code, notes, and snippets.

@michimani
Created June 12, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michimani/8a9234cf2345b31bbedc9b9f58c77fac to your computer and use it in GitHub Desktop.
Save michimani/8a9234cf2345b31bbedc9b9f58c77fac to your computer and use it in GitHub Desktop.
Sample Google Apps Script that set Slack status emoji and message.
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