@minesa-org/mini-interaction 0.2.15 → 0.2.16

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.
@@ -45,7 +45,7 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
45
45
  };
46
46
  options: CommandInteractionOptionResolver;
47
47
  getResponse(): APIInteractionResponse | null;
48
- reply(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource;
48
+ reply(data: InteractionMessageData): Promise<APIInteractionResponseChannelMessageWithSource>;
49
49
  edit(data?: InteractionMessageData): APIInteractionResponseUpdateMessage;
50
50
  followUp(data: InteractionMessageData): Promise<void>;
51
51
  editReply(data?: InteractionMessageData): Promise<void>;
@@ -251,13 +251,13 @@ export function createCommandInteraction(interaction, helpers) {
251
251
  getResponse() {
252
252
  return capturedResponse;
253
253
  },
254
- reply(data) {
254
+ async reply(data) {
255
255
  if (this.canRespond && !this.canRespond(this.id)) {
256
256
  throw new Error('Interaction cannot respond: already responded or expired');
257
257
  }
258
258
  const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
259
259
  if (isDeferred && this.sendFollowUp) {
260
- this.sendFollowUp(this.token, response, '@original');
260
+ await this.sendFollowUp(this.token, response, '@original');
261
261
  }
262
262
  else {
263
263
  this.onAck?.(response);
@@ -5,7 +5,7 @@ import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageH
5
5
  */
6
6
  export type ContextMenuInteractionHelpers = {
7
7
  getResponse: () => APIInteractionResponse | null;
8
- reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource;
8
+ reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
9
9
  followUp: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
10
10
  editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
11
11
  deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
@@ -27,13 +27,13 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
27
27
  }
28
28
  return captureResponse({ type });
29
29
  }
30
- const reply = (data) => {
30
+ const reply = async (data) => {
31
31
  if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
32
32
  throw new Error("[MiniInteraction] Interaction cannot respond: already responded or expired");
33
33
  }
34
34
  const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
35
35
  if (isDeferred && helpers?.sendFollowUp) {
36
- helpers.sendFollowUp(interaction.token, response, '@original');
36
+ await helpers.sendFollowUp(interaction.token, response, '@original');
37
37
  }
38
38
  else {
39
39
  helpers?.onAck?.(response);
@@ -153,6 +153,10 @@ export type MessageComponentInteraction = APIMessageComponentInteraction & {
153
153
  showModal: (data: APIModalInteractionResponseCallbackData | {
154
154
  toJSON(): APIModalInteractionResponseCallbackData;
155
155
  }) => APIModalInteractionResponse;
156
+ /**
157
+ * Edit the initial interaction response.
158
+ */
159
+ editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage | APIInteractionResponseChannelMessageWithSource>;
156
160
  /**
157
161
  * Finalise the interaction response via a webhook follow-up.
158
162
  * This is automatically called by reply() and update() if the interaction is deferred.
@@ -108,6 +108,29 @@ export function createMessageComponentInteraction(interaction, helpers) {
108
108
  data: resolvedData,
109
109
  });
110
110
  };
111
+ const editReply = async (data) => {
112
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
113
+ throw new Error("[MiniInteraction] Interaction cannot edit reply: expired");
114
+ }
115
+ const normalisedData = normaliseInteractionMessageData(data);
116
+ const response = captureResponse(normalisedData
117
+ ? {
118
+ type: InteractionResponseType.ChannelMessageWithSource,
119
+ data: normalisedData,
120
+ }
121
+ : {
122
+ type: InteractionResponseType.ChannelMessageWithSource,
123
+ data: { content: "" }
124
+ });
125
+ if (helpers?.sendFollowUp) {
126
+ await helpers.sendFollowUp(interaction.token, response, "@original");
127
+ }
128
+ else {
129
+ helpers?.onAck?.(response);
130
+ }
131
+ helpers?.trackResponse?.(interaction.id, interaction.token, "responded");
132
+ return response;
133
+ };
111
134
  const getResponse = () => capturedResponse;
112
135
  // Extract values from select menu interactions
113
136
  const values = "values" in interaction.data ? interaction.data.values : undefined;
@@ -210,6 +233,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
210
233
  update,
211
234
  deferUpdate,
212
235
  showModal,
236
+ editReply,
213
237
  getResponse,
214
238
  values,
215
239
  getStringValues,
@@ -21,6 +21,10 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
21
21
  */
22
22
  canRespond?: (interactionId: string) => boolean;
23
23
  trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
24
+ /**
25
+ * Edit the initial interaction response.
26
+ */
27
+ editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
24
28
  };
25
29
  export declare const ModalSubmitInteraction: {};
26
30
  /**
@@ -25,7 +25,21 @@ export function createModalSubmitInteraction(interaction, helpers) {
25
25
  data: normalisedData,
26
26
  });
27
27
  if (isDeferred && helpers?.sendFollowUp) {
28
- await helpers.sendFollowUp(interaction.token, response, '');
28
+ await helpers.sendFollowUp(interaction.token, response, '@original');
29
+ }
30
+ else {
31
+ helpers?.onAck?.(response);
32
+ }
33
+ return response;
34
+ };
35
+ const editReply = async (data) => {
36
+ const normalisedData = normaliseInteractionMessageData(data);
37
+ const response = captureResponse({
38
+ type: InteractionResponseType.ChannelMessageWithSource,
39
+ data: normalisedData ?? { content: "" },
40
+ });
41
+ if (helpers?.sendFollowUp) {
42
+ await helpers.sendFollowUp(interaction.token, response, '@original');
29
43
  }
30
44
  else {
31
45
  helpers?.onAck?.(response);
@@ -64,6 +78,7 @@ export function createModalSubmitInteraction(interaction, helpers) {
64
78
  return Object.assign(interaction, {
65
79
  reply,
66
80
  deferReply,
81
+ editReply,
67
82
  getResponse,
68
83
  getTextFieldValue,
69
84
  sendFollowUp: helpers?.sendFollowUp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
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",