Created
March 4, 2019 08:22
-
-
Save vwrs/86b089407d2311f40f5270bf63b8e2ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
import os | |
import dotenv | |
from slackclient import SlackClient | |
dotenv.load_dotenv('/path/to/.env') | |
def post_slack(text: str, channel: str): | |
slack_token = os.environ['SLACK_API_TOKEN'] | |
sc = SlackClient(slack_token) | |
return sc.api_call( | |
'chat.postMessage', | |
channel=channel, | |
text=text | |
) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('usage: python', sys.argv[0], 'TEXT') | |
exit(1) | |
ret = post_slack(text=sys.argv[1], channel='mychannel') | |
if not ret['ok']: | |
print('SLACK_API_ERROR: ', ret['error']) | |
else: | |
print('SUCCESS') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment