Skip to content

Commit 58ee480

Browse files
feat: ✨ cancel button added
1 parent 9bfeed3 commit 58ee480

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ app.post('/slack/giffy', async (c) => {
8282
action_id: 'another_gif',
8383
value: JSON.stringify({ text }),
8484
},
85+
{
86+
type: 'button',
87+
text: { type: 'plain_text', text: 'Cancel' },
88+
action_id: 'cancel',
89+
value: JSON.stringify({}),
90+
},
8591
],
8692
},
8793
{
@@ -209,6 +215,12 @@ app.post('/slack/interactive', async (c) => {
209215
action_id: 'another_gif',
210216
value: JSON.stringify({ text }),
211217
},
218+
{
219+
type: 'button',
220+
text: { type: 'plain_text', text: 'Cancel' },
221+
action_id: 'cancel',
222+
value: JSON.stringify({}),
223+
},
212224
],
213225
},
214226
{
@@ -231,6 +243,30 @@ app.post('/slack/interactive', async (c) => {
231243
text: 'Failed to send the GIF. Please try again.',
232244
});
233245
}
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+
}
234270
}
235271

236272
return c.json({ text: 'Action not recognized' });

0 commit comments

Comments
 (0)