@@ -82,6 +82,12 @@ app.post('/slack/giffy', async (c) => {
82
82
action_id : 'another_gif' ,
83
83
value : JSON . stringify ( { text } ) ,
84
84
} ,
85
+ {
86
+ type : 'button' ,
87
+ text : { type : 'plain_text' , text : 'Cancel' } ,
88
+ action_id : 'cancel' ,
89
+ value : JSON . stringify ( { } ) ,
90
+ } ,
85
91
] ,
86
92
} ,
87
93
{
@@ -209,6 +215,12 @@ app.post('/slack/interactive', async (c) => {
209
215
action_id : 'another_gif' ,
210
216
value : JSON . stringify ( { text } ) ,
211
217
} ,
218
+ {
219
+ type : 'button' ,
220
+ text : { type : 'plain_text' , text : 'Cancel' } ,
221
+ action_id : 'cancel' ,
222
+ value : JSON . stringify ( { } ) ,
223
+ } ,
212
224
] ,
213
225
} ,
214
226
{
@@ -231,6 +243,30 @@ app.post('/slack/interactive', async (c) => {
231
243
text : 'Failed to send the GIF. Please try again.' ,
232
244
} ) ;
233
245
}
246
+ } else if ( action && action . action_id === 'cancel' ) {
247
+ try {
248
+ await fetch ( responseUrl , {
249
+ method : 'POST' ,
250
+ headers : { 'Content-Type' : 'application/json' } ,
251
+ body : JSON . stringify ( {
252
+ response_type : 'in_channel' ,
253
+ delete_original : true ,
254
+ } ) ,
255
+ } ) ;
256
+
257
+ return c . json ( {
258
+ response_type : 'ephemeral' ,
259
+ delete_original : true ,
260
+ replace_original : true ,
261
+ text : '' ,
262
+ } ) ;
263
+ } catch ( error ) {
264
+ console . error ( 'Error posting GIF:' , error ) ;
265
+ return c . json ( {
266
+ response_type : 'ephemeral' ,
267
+ text : 'Please try again, or directly delete the message for now' ,
268
+ } ) ;
269
+ }
234
270
}
235
271
236
272
return c . json ( { text : 'Action not recognized' } ) ;
0 commit comments