@minesa-org/mini-interaction 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,6 +101,10 @@ export class MiniInteraction {
101
101
  this.trackInteractionState(interactionId, state.token, 'expired');
102
102
  return false;
103
103
  }
104
+ // Initial response only allowed once if not deferred
105
+ if (state.state === 'responded' && !state.token) {
106
+ return false;
107
+ }
104
108
  return true;
105
109
  }
106
110
  /**
@@ -1267,7 +1271,7 @@ export class MiniInteraction {
1267
1271
  canRespond: (id) => this.canRespond(id),
1268
1272
  trackResponse: (id, token, state) => this.trackInteractionState(id, token, state),
1269
1273
  onAck: (response) => ackResolver?.(response),
1270
- sendFollowUp: (token, response, messageId) => this.sendFollowUp(token, response, messageId),
1274
+ sendFollowUp,
1271
1275
  });
1272
1276
  response = await command.handler(interactionWithHelpers);
1273
1277
  resolvedResponse =
@@ -1391,7 +1395,10 @@ export class MiniInteraction {
1391
1395
  }
1392
1396
  if (!fetchResponse.ok) {
1393
1397
  const errorBody = await fetchResponse.text();
1394
- console.error(`[MiniInteraction] Failed to send follow-up response: [${fetchResponse.status}] ${errorBody}`);
1398
+ console.error(`[MiniInteraction] Failed to send follow-up response (id=${messageId || 'new'}): [${fetchResponse.status}] ${errorBody}`);
1399
+ if (fetchResponse.status === 404) {
1400
+ console.error("[MiniInteraction] Hint: Interaction token might have expired or the message was deleted.");
1401
+ }
1395
1402
  }
1396
1403
  }
1397
1404
  catch (error) {
@@ -256,9 +256,14 @@ export function createCommandInteraction(interaction, helpers) {
256
256
  throw new Error('Interaction cannot respond: already responded or expired');
257
257
  }
258
258
  const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
259
+ if (isDeferred && this.sendFollowUp) {
260
+ this.sendFollowUp(this.token, response, '@original');
261
+ }
262
+ else {
263
+ this.onAck?.(response);
264
+ }
259
265
  this.trackResponse?.(this.id, this.token, 'responded');
260
266
  hasResponded = true;
261
- this.onAck?.(response);
262
267
  return response;
263
268
  },
264
269
  async followUp(data) {
@@ -273,6 +278,8 @@ export function createCommandInteraction(interaction, helpers) {
273
278
  if (this.sendFollowUp) {
274
279
  await this.sendFollowUp(this.token, response, '');
275
280
  }
281
+ this.trackResponse?.(this.id, this.token, 'responded');
282
+ hasResponded = true;
276
283
  },
277
284
  edit(data) {
278
285
  return createMessageResponse(InteractionResponseType.UpdateMessage, data);
@@ -281,17 +288,21 @@ export function createCommandInteraction(interaction, helpers) {
281
288
  if (this.canRespond && !this.canRespond(this.id)) {
282
289
  throw new Error('Interaction cannot edit reply: expired');
283
290
  }
284
- const normalisedData = normaliseInteractionMessageData(data);
285
- if (!normalisedData) {
291
+ const normalizedData = normaliseInteractionMessageData(data);
292
+ if (!normalizedData) {
286
293
  throw new Error('[MiniInteraction] editReply requires data');
287
294
  }
288
295
  const response = {
289
296
  type: InteractionResponseType.ChannelMessageWithSource,
290
- data: normalisedData,
297
+ data: normalizedData,
291
298
  };
292
- if (this.sendFollowUp) {
299
+ if (this.sendFollowUp && (isDeferred || hasResponded)) {
293
300
  await this.sendFollowUp(this.token, response, '@original');
294
301
  }
302
+ else {
303
+ captureResponse(response);
304
+ this.onAck?.(response);
305
+ }
295
306
  this.trackResponse?.(this.id, this.token, 'responded');
296
307
  hasResponded = true;
297
308
  },
@@ -32,9 +32,14 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
32
32
  throw new Error("[MiniInteraction] Interaction cannot respond: already responded or expired");
33
33
  }
34
34
  const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
35
+ if (isDeferred && helpers?.sendFollowUp) {
36
+ helpers.sendFollowUp(interaction.token, response, '@original');
37
+ }
38
+ else {
39
+ helpers?.onAck?.(response);
40
+ }
35
41
  hasResponded = true;
36
42
  helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
37
- helpers?.onAck?.(response);
38
43
  return response;
39
44
  };
40
45
  const followUp = async (data) => {
@@ -42,6 +47,8 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
42
47
  if (helpers?.sendFollowUp) {
43
48
  await helpers.sendFollowUp(interaction.token, response, '');
44
49
  }
50
+ hasResponded = true;
51
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
45
52
  return response;
46
53
  };
47
54
  const editReply = async (data) => {
@@ -55,6 +62,8 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
55
62
  await helpers.sendFollowUp(interaction.token, response, '@original');
56
63
  return capturedResponse;
57
64
  }
65
+ captureResponse(response);
66
+ helpers?.onAck?.(response);
58
67
  hasResponded = true;
59
68
  helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
60
69
  return response;
@@ -36,7 +36,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
36
36
  data: normalisedData,
37
37
  });
38
38
  if (isDeferred && helpers?.sendFollowUp) {
39
- await helpers.sendFollowUp(interaction.token, response, '');
39
+ await helpers.sendFollowUp(interaction.token, response, '@original');
40
40
  }
41
41
  else {
42
42
  helpers?.onAck?.(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",