Skip to content

Instantly share code, notes, and snippets.

@MatejMecka
Last active November 28, 2017 18:43
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 MatejMecka/153c0bbb79e70bd33323fea6c06a781f to your computer and use it in GitHub Desktop.
Save MatejMecka/153c0bbb79e70bd33323fea6c06a781f to your computer and use it in GitHub Desktop.
GCI17 CCExtractor Development
# -*- coding: utf-8 -*-
# To start bot install SlackClient from pip. Make sure bot joins #general only! Leave it to run. Use supervisor i'd recommmend
from slackclient import SlackClient
import time
slack_token = "" #token for slack
sc = SlackClient(slack_token)
messagetosend = "" #message to great
if sc.rtm_connect():
while True:
for slack_message in sc.rtm_read():
print(slack_message)
message = slack_message.get("type")
user = slack_message.get("user")
if not message or not user:
continue
if message == "member_joined_channel":
sc.api_call("chat.postMessage",channel=user,as_user=True,text=messagetosend)
time.sleep(2)
else:
print("There is a problem connecting to Slack. Check your Internet connection or you might have problems with the API key.")
@MatejMecka
Copy link
Author

MatejMecka commented Nov 28, 2017

You can start the bot by installing slackclient using pip install slackclient
Get a Slack token by creating a bot user.(https://my.slack.com/services/new/bot)
Modify the messagetosend variable to include the greeting message to dm a user.
python bot.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment