4
4
from utils .log_manager import setup_logging
5
5
from decouple import config
6
6
import traceback
7
+ from pprint import pprint
8
+
7
9
8
10
from src .help_menu import HELP_MENU_RESPONSES
9
- from src .messages import HELP_MENU , MESSAGE , needs_greet_button , greeted_response_attachments
11
+ from src .messages import HELP_MENU , MESSAGE , needs_greet_button , greeted_response_attachments , SUGGESTION_MODAL
10
12
11
13
logger = logging .getLogger (__name__ )
12
14
new_event_logger = logging .getLogger (f'{ __name__ } .new_member' )
19
21
# COMMUNITY_CHANNEL = config('PERSONAL_PRIVATE_CHANNEL')
20
22
21
23
TOKEN = config ('OPCODE_APP_TOKEN' )
22
- COMMUNITY_CHANNEL = config ('OPCODE_REWRITE_CHANNEL' )
23
- PROJECTS_CHANNEL = config ('OPCODE_OC_PROJECTS_CHANNEL' )
24
+ # COMMUNITY_CHANNEL = config('OPCODE_REWRITE_CHANNEL')
25
+ # PROJECTS_CHANNEL = config('OPCODE_OC_PROJECTS_CHANNEL')
24
26
# COMMUNITY_CHANNEL = config('OPCODE_COMMUNITY_ID')
27
+ COMMUNITY_CHANNEL = config ('OPCODE_BOT_TESTING_CHANNEL' )
25
28
26
29
PROXY = PROXY if PROXY else None
27
30
slack_client = SlackClient (TOKEN , proxies = PROXY )
@@ -39,9 +42,9 @@ def event_handler(event_dict: dict) -> None:
39
42
:param event_dict:
40
43
"""
41
44
# all_event_logger.info(event_dict)
42
- if event_dict ['type' ] == 'team_join' :
43
- new_event_logger .info ('New member event recieved' )
44
- new_member (event_dict )
45
+ # if event_dict['type'] == 'team_join':
46
+ # new_event_logger.info('New member event recieved')
47
+ # new_member(event_dict)
45
48
46
49
""" Trigger for testing team_join event """
47
50
if event_dict ['type' ] == 'message' and 'user' in event_dict .keys () and event_dict ['text' ] == 'testgreet' :
@@ -55,12 +58,21 @@ def help_menu_interaction(data: dict) -> None:
55
58
displayed message
56
59
:param data:
57
60
"""
58
- params = {'text' : ' \n \n \n ' + HELP_MENU_RESPONSES [data ['actions' ][0 ]['value' ]],
59
- 'channel' : data ['channel' ]['id' ],
60
- 'ts' : data ['message_ts' ],
61
- 'as_user' : True
62
- }
63
- slack_client .api_call ('chat.update' , ** params )
61
+
62
+ response = data ['actions' ][0 ]['value' ]
63
+
64
+ if response == 'suggestion' :
65
+ trigger_id = data ['trigger_id' ]
66
+ res = slack_client .api_call ('dialog.open' , trigger_id = trigger_id , dialog = SUGGESTION_MODAL )
67
+ pprint (res )
68
+
69
+ else :
70
+ params = {'text' : ' \n \n \n ' + HELP_MENU_RESPONSES [data ['actions' ][0 ]['value' ]],
71
+ 'channel' : data ['channel' ]['id' ],
72
+ 'ts' : data ['message_ts' ],
73
+ 'as_user' : True
74
+ }
75
+ slack_client .api_call ('chat.update' , ** params )
64
76
65
77
66
78
def greeted_interaction (data : dict ) -> dict :
@@ -91,6 +103,13 @@ def greeted_interaction(data: dict) -> dict:
91
103
res = slack_client .api_call ("chat.update" , ** params )
92
104
93
105
106
+ def suggestion_submission (data ):
107
+ suggestion = data ['submission' ]['suggestion' ]
108
+ user_id = data ['user' ]['id' ]
109
+ message = f"<@{ user_id } > just submitted a suggestion for a help topic:\n { suggestion } "
110
+ res = slack_client .api_call ('chat.postMessage' , channel = COMMUNITY_CHANNEL , text = message )
111
+
112
+
94
113
def new_member (event_dict : dict ) -> None :
95
114
new_event_logger .info ('Recieved json event: {}' .format (event_dict ))
96
115
@@ -102,27 +121,27 @@ def new_member(event_dict: dict) -> None:
102
121
custom_message = MESSAGE .format (real_name = real_name )
103
122
104
123
new_event_logger .info ('Built message: {}' .format (custom_message ))
105
- response = slack_client .api_call ('chat.postMessage' ,
106
- channel = user_id ,
107
- # channel=COMMUNITY_CHANNEL, # testing option
108
- # as_user=True, # Currently not working. DM comes from my account
109
- text = custom_message )
124
+ # response = slack_client.api_call('chat.postMessage',
125
+ # # channel=user_id,
126
+ # channel=COMMUNITY_CHANNEL, # testing option
127
+ # # as_user=True, # Currently not working. DM comes from my account
128
+ # text=custom_message)
110
129
111
130
r2 = slack_client .api_call ('chat.postMessage' ,
112
- channel = user_id ,
113
- # channel=COMMUNITY_CHANNEL, # testing option
131
+ # channel=user_id,
132
+ channel = COMMUNITY_CHANNEL , # testing option
114
133
# as_user=True,
115
134
** HELP_MENU )
116
135
117
136
# Notify #community
118
137
text = f":tada: <@{ user_id } > has joined the Slack team :tada:"
119
138
slack_client .api_call ('chat.postMessage' , channel = COMMUNITY_CHANNEL ,
120
139
text = text , attachments = needs_greet_button ())
121
-
122
- if response ['ok' ]:
123
- new_event_logger .info ('New Member Slack response: Response 1: {} \n Response2: {}' .format (response , r2 ))
124
- else :
125
- new_event_logger .error ('FAILED -- Message to new member returned error: {}' .format (response ))
140
+ #
141
+ # if response['ok']:
142
+ # new_event_logger.info('New Member Slack response: Response 1: {} \nResponse2: {}'.format(response, r2))
143
+ # else:
144
+ # new_event_logger.error('FAILED -- Message to new member returned error: {}'.format(response))
126
145
127
146
128
147
def parse_slack_output (slack_rtm_output : list ) -> None :
@@ -157,10 +176,10 @@ def join_channels():
157
176
"""
158
177
response = slack_client .api_call ('channels.join' , name = 'general' )
159
178
print (response )
179
+ # set the defalt to a 1 second delay
160
180
161
181
162
- # set the defalt to a 1 second delay
163
- def run_bot (delay : int = 1 ) -> None :
182
+ def run_bot (delay : int = 1 ) -> None :
164
183
"""
165
184
Runs the bot using the Slack Real Time Messaging API.
166
185
**Doesn't provide events or interactive functionality
@@ -183,4 +202,4 @@ def run_bot(delay: int=1) -> None:
183
202
184
203
185
204
if __name__ == '__main__' :
186
- run_bot ()
205
+ run_bot ()
0 commit comments