Changing Slack Status using Google Apps Script

This script changes slack status using GAS. If you want to change it on time you decided, it can be achieved by installing this method as a trigger.

In order to use this, the required scope is users.profile:write.

function setSlackStatus(token, user, status_text, status_emoji) {
  return UrlFetchApp.fetch(
    'https://slack.com/api/users.profile.set',
    {
      method: 'post',
      payload: {
        token: token,
        user: user,
        profile: JSON.stringify({status_text: status_text, status_emoji: status_emoji})
      },
      muteHttpExceptions: true
    }
  ).getContentText();
}

function main() {
  var res = setSlackStatus(
    '### Your access token ###',
    '### User ID ###',
    'sample',
    ':coffee:'
  );
  Logger.log(res)
}