@@ -59,10 +59,7 @@ app.event("message", async ({ event, client }) => {
59
59
// Ignore everything except new messages
60
60
return ;
61
61
}
62
-
63
- const encodedText = btoa ( event . text ) ;
64
62
console . log ( "Posting an ephemeral message to user:" , event . user , "in channel:" , event . channel ) ;
65
-
66
63
try {
67
64
// Respond with an ephemeral message containing a dropdown menu
68
65
await client . chat . postEphemeral ( {
@@ -78,7 +75,7 @@ app.event("message", async ({ event, client }) => {
78
75
} ,
79
76
accessory : {
80
77
type : "external_select" ,
81
- action_id : `category_select-${ encodedText } ` ,
78
+ action_id : `category_select-${ event . ts } ` ,
82
79
placeholder : {
83
80
type : "plain_text" ,
84
81
text : "Select a category" ,
@@ -137,12 +134,20 @@ app.action(/category_select-.*/, async ({ body, ack, say }) => {
137
134
// Acknowledge the action
138
135
await ack ( ) ;
139
136
console . log ( "body" , body ) ;
140
- const text = atob ( body . actions [ 0 ] . action_id . split ( "-" ) [ 1 ] ) ;
137
+ // const text = atob(body.actions[0].action_id.split("-")[1]); Currently not used since it caused bugs, so text is just an empty string
138
+ const text = "" ;
141
139
console . log ( "text" , text ) ;
142
140
// Respond to the user's selection
143
141
const selectedCategory = body . actions [ 0 ] . selected_option . text . text ;
144
142
const dropdown_id = body . actions [ 0 ] . action_id ;
145
- addOrUpdateInc ( body . user . username , text , selectedCategory , dropdown_id ) ;
143
+ try {
144
+ addOrUpdateInc ( body . user . username , text , selectedCategory , dropdown_id ) ;
145
+ await say ( `You selected: ${ selectedCategory } ` ) ;
146
+ } catch ( error ) {
147
+ say ( "There was an error adding the incident. Please try again later." ) ;
148
+ console . error ( "Error adding incident:" , error ) ;
149
+ }
150
+
146
151
} ) ;
147
152
148
153
0 commit comments