Skip to content

Instantly share code, notes, and snippets.

@Lokno
Created September 7, 2017 16:55
Show Gist options
  • Save Lokno/777d4d6b31d6564c2806f7189c9ab213 to your computer and use it in GitHub Desktop.
Save Lokno/777d4d6b31d6564c2806f7189c9ab213 to your computer and use it in GitHub Desktop.
Command-line utility for posting a message as a slack bot
import os,sys
from slackclient import SlackClient
if len(sys.argv) < 2:
print "usage: post_as_bot.py <message>"
sys.exit(-1)
msg = ' '.join(sys.argv[1:])
BOT_NAME = 'BOTNAME'
slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))
if __name__ == "__main__":
slack_client.api_call("chat.postMessage", channel='CHANNEL', text=msg, as_user=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment