22from time import time
33from typing import List
44
5- from slack .events import Message
5+ from pybot . endpoints . slack .utils import MODERATOR_CHANNEL
66
7- from pybot .endpoints .slack .utils import REPORT_CHANNEL
7+ TICKET_OPTIONS = {
8+ 'notStarted' : 'Not Started' ,
9+ 'inProgress' : 'In-progress' ,
10+ 'waitingOnUser' : 'Waiting on User' ,
11+ 'complete' : 'Complete'
12+ }
813
914
1015def now ():
@@ -16,14 +21,57 @@ def now():
1621
1722
1823def base_response (action ):
19- response = Message ()
24+ response = {
25+ 'text' : action ['original_message' ].get ('text' , None ),
26+ 'channel' : action ['channel' ]['id' ],
27+ 'ts' : action ['message_ts' ],
28+ }
29+ return response
30+
31+
32+ def updated_ticket_status (action ):
33+ selected_option = action ['actions' ][0 ]['selected_options' ][0 ]
34+ selected_option ['text' ] = TICKET_OPTIONS [selected_option ['value' ]]
2035
21- response ['text' ] = action ['original_message' ]['text' ]
22- response ['channel' ] = action ['channel' ]['id' ]
23- response ['ts' ] = action ['message_ts' ]
36+ updated_attachments = action ['original_message' ]['attachments' ]
37+ updated_attachments [0 ]['actions' ][0 ]['selected_options' ] = [selected_option ]
38+ response = {
39+ ** base_response (action ),
40+ 'attachments' : updated_attachments
41+ }
2442 return response
2543
2644
45+ def ticket_attachments (action ):
46+ user_id = action ['user' ]['id' ]
47+ request_type = action ['submission' ]['type' ]
48+ email = action ['submission' ]['email' ]
49+ details = action ['submission' ]['details' ]
50+ attachments = [
51+ {
52+ 'text' : '' ,
53+ 'callback_id' : 'ticket_status' ,
54+ "response_type" : "in_channel" ,
55+ "fallback" : "request details should have been here" ,
56+ "fields" : [
57+ {"title" : "User" , "value" : f"<@{ user_id } >" , "short" : True },
58+ {"title" : "Email" , "value" : f"{ email } " , "short" : True },
59+ {"title" : "Request Type" , "value" : f"{ request_type } " , "short" : True },
60+ {"title" : "Details" , "value" : f"{ details } " , "short" : True },
61+ ],
62+ 'actions' : [
63+ {
64+ 'name' : 'status' , 'text' : 'Current Status' , 'type' : 'select' ,
65+ 'selected_options' : [{'text' : 'Not Started' , 'value' : 'notStarted' }],
66+ 'options' : [{'text' : text , 'value' : value } for value , text in TICKET_OPTIONS .items ()]
67+ }
68+ ]
69+ },
70+ not_claimed_attachment ()
71+ ]
72+ return attachments
73+
74+
2775def greeted_attachment (user_id : str ) -> List [dict ]:
2876 return [{
2977 "text" : f":100:<@{ user_id } > has greeted the new user!:100:\n "
@@ -60,24 +108,25 @@ def not_greeted_attachment():
60108
61109
62110def not_claimed_attachment ():
63- return [ {
111+ return {
64112 'text' : "" ,
65- "fallback" : "" ,
113+ "fallback" : "not claimed attachment " ,
66114 "color" : "#3AA3E3" ,
67115 "callback_id" : "claimed" ,
68116 "attachment_type" : "default" ,
117+ 'short' : True ,
69118 "actions" : [{
70119 "name" : "claimed" ,
71120 "text" : "Claim" ,
72121 "type" : "button" ,
73122 "style" : "primary" ,
74123 "value" : "claimed"
75124 }]
76- }]
125+ }
77126
78127
79128def claimed_attachment (user_id ):
80- return [ {
129+ return {
81130 "text" : f"Claimed by <@{ user_id } >\n "
82131 f"<!date^{ now ()} ^Claimed at {{date_num}} {{time_secs}}|Failed to parse time>" ,
83132 "fallback" : "" ,
@@ -91,7 +140,7 @@ def claimed_attachment(user_id):
91140 "style" : "danger" ,
92141 "value" : "reset_claim" ,
93142 }]
94- }]
143+ }
95144
96145
97146def reset_greet_message (user_id ):
@@ -165,7 +214,7 @@ def build_report_message(slack_id, details, message_details):
165214
166215 return {
167216 "text" : message ,
168- "channel" : REPORT_CHANNEL ,
217+ "channel" : MODERATOR_CHANNEL ,
169218 "attachments" : attachment
170219 }
171220
0 commit comments