Skip to content

Commit

Permalink
1.updated deprecated slack api call(https://slack.com/api/im.open)
Browse files Browse the repository at this point in the history
    with https://slack.com/api/conversations.open.
    2. Fixed bug on line 75 which was setting dictionary data to None
    3. changed variable name to be more desciptive on line number 59 and
    77
  • Loading branch information
yougaindra committed Oct 2, 2020
1 parent e755200 commit a03d2e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ If you have questions open an `Issue` (preferred) or reply to the tutorial artic

# Requirements
Python 2.7+
Edit `bot.py` on lines 7-8 to customise with your greeting and token
Edit `bot.py` on lines 27-29 to customise with your greeting and token

# Installation
```bash
Expand Down
18 changes: 9 additions & 9 deletions bot.py
Expand Up @@ -21,7 +21,7 @@
TOKEN = os.environ.get('SLACK_TOKEN')
CHANNEL_TOKEN = os.environ.get('CHANNEL_TOKEN')
UNFURL = os.environ.get('UNFURL_LINKS')
RESPONSE_CHANNEL = os.environ.get('RESPONSE_CHANNEL')
RESPONSE_CHANNEL = os.environ.get('RESPONSE_CHANNEL')
DEBUG_CHANNEL_ID = os.environ.get('DEBUG_CHANNEL_ID', False)
except:
MESSAGE = 'Manually set the Message if youre not running through heroku or have not set vars in ENV'
Expand All @@ -36,7 +36,7 @@ def is_debug_channel_join(msg):
return msg['type'] == "member_joined_channel" and msg['channel'] == DEBUG_CHANNEL_ID and msg['channel_type'] == 'C'

def is_direct_message(msg):
print msg
print(msg)
is_bot = False
if 'bot_id' in msg:
is_bot = True
Expand All @@ -56,14 +56,14 @@ def parse_join(message):
if is_team_join(m) or is_debug_channel_join(m):
user_id = m["user"]["id"] if is_team_join(m) else m["user"]
logging.debug(m)
x = requests.get("https://slack.com/api/im.open?token="+TOKEN+"&user="+user_id)
x = x.json()
x = x["channel"]["id"]
logging.debug(x)
conversation = requests.post("https://slack.com/api/conversations.open?token=" + TOKEN + "&users=" + "UL5JGPBC2",
data=None).json()
conversation_channel = conversation["channel"]["id"]
logging.debug(conversation_channel)

data = {
'token': TOKEN,
'channel': x,
'channel': conversation_channel,
'text': MESSAGE,
'parse': 'full',
'as_user': 'true',
Expand All @@ -72,9 +72,9 @@ def parse_join(message):
logging.debug(data)

if (UNFURL.lower() == "false"):
data = data.update({'unfurl_link': 'false'})
data.update({'unfurl_link': 'false'})

xx = requests.post("https://slack.com/api/chat.postMessage", data=data)
post_message_response = requests.post("https://slack.com/api/chat.postMessage", data=data)
logging.debug('\033[91m' + "HELLO SENT TO " + m["user"]["id"] + '\033[0m')

if is_direct_message(m):
Expand Down

0 comments on commit a03d2e3

Please sign in to comment.