Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved ClientMessageRequest typing #394

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading