Skip to content

Instantly share code, notes, and snippets.

@jattoabdul
Created July 10, 2018 17:56
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 jattoabdul/3fd95483423b8be6f31cb8dcfb56250b to your computer and use it in GitHub Desktop.
Save jattoabdul/3fd95483423b8be6f31cb8dcfb56250b to your computer and use it in GitHub Desktop.
Slack API helpers for our application using SlackClient as a python wrapper.
from slackclient import SlackClient
from config import get_env
class SlackHelper:
def __init__(self):
self.slack_token = get_env('SLACK_TOKEN')
self.slack_client = SlackClient(self.slack_token)
self.slack_channel = get_env('SLACK_CHANNEL')
def post_message(self, msg, recipient):
return self.slack_client.api_call(
"chat.postMessage",
channel=recipient,
text=msg,
as_user=True
)
def post_message_to_channel(self, msg):
return self.slack_client.api_call(
"chat.postMessage",
channel=self.slack_channel,
text=msg,
username='Ranti',
parse='full',
as_user=False
)
def file_upload(self, file_content, file_name, file_type, title=None, ):
return self.slack_client.api_call(
"files.upload",
channels=self.slack_channel,
content=file_content,
filename=file_name,
filetype=file_type,
initial_comment='{} Log File'.format(file_name),
title=title
)
def user_info(self, uid):
return self.slack_client.api_call(
"users.info",
user=uid,
token=self.slack_token
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment