Skip to content

Commit

Permalink
Merge pull request #394 from Secreto31126/type-fix
Browse files Browse the repository at this point in the history
Improved ClientMessageRequest typing
  • Loading branch information
Secreto31126 authored Dec 31, 2024
2 parents c8befb6 + 77115c3 commit de88cf6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ export class WhatsAppAPI<EmittersReturnType = void> {
to
} as ClientMessageRequest;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - TS dumb, the _type will always match the type
request[type] = message;

if (context) request.context = { message_id: context };
Expand Down
92 changes: 47 additions & 45 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,52 +383,54 @@ export type ClientMessageRequest = {
* Cloud API does not process this field, it just returns it as part of sent/delivered/read message webhooks.
*/
biz_opaque_callback_data?: string;
} & {
[Type in ClientMessageNames]?: ClientMessage;
} & (
| {
type: "text";
text?: Text;
}
| {
type: "audio";
audio?: Audio;
}
| {
type: "document";
document?: Document;
}
| {
type: "image";
image?: Image;
}
| {
type: "sticker";
sticker?: Sticker;
}
| {
type: "video";
video?: Video;
}
| {
type: "location";
location?: Location;
}
| {
type: "contacts";
contacts?: Contacts;
}
| {
type: "interactive";
interactive?: Interactive;
}
| {
type: "template";
template?: Template;
}
| {
type: "reaction";
reaction?: Reaction;
}
);
| {
type: "text";
text: Text;
}
| {
type: "audio";
audio: Audio;
}
| {
type: "document";
document: Document;
}
| {
type: "image";
image: Image;
}
| {
type: "sticker";
sticker: Sticker;
}
| {
type: "video";
video: Video;
}
| {
type: "location";
location: Location;
}
| {
type: "contacts";
contacts: Contacts;
}
| {
type: "interactive";
interactive: Interactive;
}
| {
type: "template";
template: Template;
}
| {
type: "reaction";
reaction: Reaction;
}
);

// #endregion

Expand Down

0 comments on commit de88cf6

Please sign in to comment.