Skip to content

Commit 4e811ab

Browse files
committedFeb 25, 2018
adding back dm handling
1 parent 52a9a8d commit 4e811ab

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed
 

‎slackoverflow.py

+18-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
RTM_READ_DELAY = 1 # 1 second delay between reading from RTM
1818
CHARACTER_LIMIT = 200 # character limit for the response.
1919

20-
2120
def reply_thread(thread_ts, channel, response):
2221
title, link, text = response
2322
slack_client.api_call(
@@ -34,23 +33,20 @@ def reply_thread(thread_ts, channel, response):
3433
thread_ts=thread_ts
3534
)
3635

37-
# def post_to_channel(channel, text):
38-
# slack_client.api_call(
39-
# "chat.postMessage",
40-
# channel=channel,
41-
# attachments= [
42-
# {
43-
# "title": "slackoverflow", # TODO: change pretext and title lol
44-
# "pretext": "Adam",
45-
# "text": text,
46-
# "mrkdwn_in": ["text"]
47-
# }
48-
# ]
49-
# )
50-
51-
# OPTIONAL: Need to be able to reply to the parent's thread ts.
52-
# OPTIONAL: Add reactions to indicate progress and completeness.
53-
36+
def post_to_channel(channel, response):
37+
title, link, text = response
38+
slack_client.api_call(
39+
"chat.postMessage",
40+
channel=channel,
41+
attachments= [
42+
{
43+
"title": title,
44+
"pretext": link,
45+
"text": text,
46+
"mrkdwn_in": ["text"]
47+
}
48+
]
49+
)
5450

5551
def parse_events(slack_events):
5652
for event in slack_events:
@@ -64,15 +60,13 @@ def parse_events(slack_events):
6460
if "text" in event:
6561
message = event["text"]
6662
# If DMing bot
67-
# if event["channel"][0] == "D":
68-
# response = generate_answer(message, True)
69-
# print(response)
70-
# post_to_channel(event["channel"], response)
63+
if event["channel"][0] == "D":
64+
response = generate_answer(message, True)
65+
post_to_channel(event["channel"], response)
7166
# If mentioning bot
72-
if bot_id in message:
67+
elif bot_id in message:
7368
message = message.replace("<@{0}>".format(bot_id), "")
7469
response = generate_answer(message, False)
75-
print(response)
7670
reply_thread(event["ts"], event["channel"], response)
7771

7872

0 commit comments

Comments
 (0)
Please sign in to comment.