Skip to content

Instantly share code, notes, and snippets.

@savkov
Created September 17, 2019 09:44
Show Gist options
  • Save savkov/08d74496dbfd9f5cf013da688a52e693 to your computer and use it in GitHub Desktop.
Save savkov/08d74496dbfd9f5cf013da688a52e693 to your computer and use it in GitHub Desktop.
Set some attributes of your slack profile automatically.
from slacker import Slacker
import os
def yellow(s):
return '\033[93m' + str(s) + '\033[0m'
try:
# How to obtain a legacy token: https://get.slack.help/hc/en-gb/articles/215770388-Create-and-regenerate-API-tokens
slack = Slacker(os.environ.get('SLACK_TOKEN'))
except:
print('You need a slack token.')
SLACK_USER = os.environ.get('SLACK_USER')
SLACK_STATUS_TEXT = os.environ.get('SLACK_STATUS_TEXT')
SLACK_STATUS_EMOJI = os.environ.get('SLACK_STATUS_EMOJI')
SLACK_HANDLE = os.environ.get('SLACK_HANDLE')
SLACK_TITLE = os.environ.get('SLACK_TITLE')
print(f'Setting up attributes for user_id "{yellow(SLACK_USER)}"')
if SLACK_STATUS_TEXT:
slack.users.profile.set(user=SLACK_USER, name='status_text', value=SLACK_STATUS_TEXT)
print(f'Set status text to "{yellow(SLACK_STATUS_TEXT)}"')
if SLACK_STATUS_EMOJI:
slack.users.profile.set(user=SLACK_USER, name='status_emoji', value=SLACK_STATUS_EMOJI)
print(f'Set status emoji to "{yellow(SLACK_STATUS_EMOJI)}"')
if SLACK_HANDLE:
slack.users.profile.set(user=SLACK_USER, name='display_name', value=SLACK_HANDLE)
print(f'Set handle to "{yellow(SLACK_HANDLE)}"')
if SLACK_TITLE:
slack.users.profile.set(user=SLACK_USER, name='title', value=SLACK_TITLE)
print(f'Set title to "{yellow(SLACK_TITLE)}"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment