17
17
RTM_READ_DELAY = 1 # 1 second delay between reading from RTM
18
18
CHARACTER_LIMIT = 200 # character limit for the response.
19
19
20
-
21
20
def reply_thread (thread_ts , channel , response ):
22
21
title , link , text = response
23
22
slack_client .api_call (
@@ -34,23 +33,20 @@ def reply_thread(thread_ts, channel, response):
34
33
thread_ts = thread_ts
35
34
)
36
35
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
+ )
54
50
55
51
def parse_events (slack_events ):
56
52
for event in slack_events :
@@ -64,15 +60,13 @@ def parse_events(slack_events):
64
60
if "text" in event :
65
61
message = event ["text" ]
66
62
# 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 )
71
66
# If mentioning bot
72
- if bot_id in message :
67
+ elif bot_id in message :
73
68
message = message .replace ("<@{0}>" .format (bot_id ), "" )
74
69
response = generate_answer (message , False )
75
- print (response )
76
70
reply_thread (event ["ts" ], event ["channel" ], response )
77
71
78
72
0 commit comments