feat: Event messages (#3345)

* feat: add createCallLink function

* feat: create Event class

* feat: add functionality for sending Events

* feat: add editEvent function

* refactor: send event location prop as wa does

* refactor: combine modules

* feat: add sendResponseToEvent function

* fix: createEventCallLink parameter

* docs: add documentation

* fix: eslint

* refactor: change timestamp to Date for the user's convenience

* refactor: rename 'Event' to 'ScheduledEvent' for more clarity

* style: fix typo in inner function

* refactor: remove unnecessary inner function

* refactor: rename 'sendResponseToEvent' to 'sendResponseToScheduledEvent' for more clarity

* fix: update the module name
This commit is contained in:
alechkos 2025-08-09 00:36:27 +03:00 • committed by GitHub
commit f9db14d185
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 261 additions and 4 deletions

74
index.d.ts vendored
View file

@ -261,6 +261,16 @@ declare namespace WAWebJS {
/** Deletes the current user's profile picture */
deleteProfilePicture(): Promise<boolean>
/** Generates a WhatsApp call link (video call or voice call) */
createCallLink(startTime: Date, callType: string): Promise<string>
/**
* Sends a response to the scheduled event message, indicating whether a user is going to attend the event or not
* @param response The response code to the event message. Valid values are: `0` for NONE response (removes a previous response) | `1` for GOING | `2` for NOT GOING | `3` for MAYBE going
* @param eventMessageId The event message ID
*/
sendResponseToScheduledEvent(response: number, eventMessageId: string): Promise<boolean>
/** Gets an array of membership requests */
getGroupMembershipRequests(groupId: string): Promise<Array<GroupMembershipRequest>>
@ -902,6 +912,7 @@ declare namespace WAWebJS {
REACTION = 'reaction',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
POLL_CREATION = 'poll_creation',
SCHEDULED_EVENT_CREATION = 'scheduled_event_creation',
}
/** Client status */
@ -1071,6 +1082,24 @@ declare namespace WAWebJS {
pollOptions: string[],
/** False for a single choice poll, true for a multiple choice poll */
allowMultipleAnswers: boolean,
/** The start time of the event in timestamp (10 digits) */
eventStartTime: number,
/** The end time of the event in timestamp (10 digits) */
eventEndTime?: number,
/** The event description */
eventDescription?: string,
/** The location of the event */
eventLocation?: {
degreesLatitude: number;
degreesLongitude: number;
name: string;
},
/** WhatsApp call link (video call or voice call) */
eventJoinLink?: string,
/** Indicates if an event should be sent as an already canceled */
isEventCaneled: boolean,
/** The custom message secret, can be used as an event ID */
messageSecret?: Array<number>,
/*
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
@ -1128,6 +1157,11 @@ declare namespace WAWebJS {
getReactions: () => Promise<ReactionList[]>,
/** Edits the current message */
edit: (content: MessageContent, options?: MessageEditOptions) => Promise<Message | null>,
/**
* Edits the current ScheduledEvent message.
* Once the event is canceled, it can not be edited.
*/
editScheduledEvent: (editedEventObject: Event) => Promise<Message | null>,
}
/** ID that represents a message */
@ -1183,6 +1217,44 @@ declare namespace WAWebJS {
constructor(pollName: string, pollOptions: Array<string>, options?: PollSendOptions)
}
/** ScheduledEvent send options */
export interface ScheduledEventSendOptions {
/** The scheduled event description */
description?: string,
/** The end time of the event */
endTime?: Date,
/** The location of the event */
location?: string,
/** The type of a WhatsApp call link to generate, valid values are: `video` | `voice` */
callType?: string,
/**
* Indicates if a scheduled event should be sent as an already canceled
* @default false
*/
isEventCanceled?: boolean
/**
* The custom message secret, can be used as an event ID
* @note It has to be a unique vector with a length of 32
*/
messageSecret: Array<number>|undefined
}
/** Represents a ScheduledEvent on WhatsApp */
export class ScheduledEvent {
name: string
startTimeTs: number
eventSendOptions: {
description?: string;
endTimeTs?: number;
location?: string;
callType?: string;
isEventCanceled?: boolean;
messageSecret?: string;
};
constructor(name: string, startTime: Date, options?: EventSendOptions)
}
/** Represents a Poll Vote on WhatsApp */
export interface PollVote {
/** The person who voted */
@ -1338,7 +1410,7 @@ declare namespace WAWebJS {
static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
}
export type MessageContent = string | MessageMedia | Location | Poll | Contact | Contact[] | List | Buttons
export type MessageContent = string | MessageMedia | Location | Poll | Contact | Contact[] | List | Buttons | ScheduledEvent
/**
* Represents a Contact on WhatsApp