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

feat: Event messages #3345

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

feat: Event messages #3345

wants to merge 11 commits into from

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Oct 22, 2024

PR Details

Description

The PR adds a new functionality for event messages:


Usage Example

1. To create and send an event message:

const { /* ... */, Event } = require('whatsapp-web.js');

// client initialization...

client.on('ready', async () => {
    const event = new Event(
        /** The event name: */
        'Birthday Party',
        /** The event start time: */
        new Date(2025, 1, 25, 15, 32),
        /** Optional properties: */
        {
            /** Event description: */
            description: 'Happy Birthday!',
            /** The event end time: */
            endTime: new Date(2025, 1, 26, 12),
            /** The location of an event: */
            location: 'Central Park',
            /** The call type ('voice' | 'video') to generate a WhatsApp call link: */
            callType: 'voice',
            /** The event can be sent as already canceled, for fun (false by default): */
            isEventCanceled: false,
            /** Can be used as an event message ID, it presents a custom array of 32 numbers, that array will be converted to Uint8Array inside the browser context: */
            messageSecret: [
                    1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                ]
        });

    const familyGroupId = '[email protected]';
    const eventMsgId = (await client.sendMessage(familyGroupId, event)).id._serialized;
});

2. To create a WhatsApp call link:

// client initialization...

client.on('ready', async () => {
    const videoCallLink = await client.createCallLink(new Date(2025, 1, 26, 12), 'video');
    console.log(videoCallLink);

    const voiceCallLink = await client.createCallLink(new Date(2025, 1, 26, 12), 'voice');
    console.log(voiceCallLink);
});

3. To respond to an event:

// client initialization...

client.on('message', async (msg) => {
    /**
     * Valid response values are:
     * 
     * 0 for NONE response (removes a previous response)
     * 1 for GOING
     * 2 for NOT GOING
     * 3 for MAYBE going
     */
    const myResponse = 1;

    if (msg.type === 'event_creation') {
        const msgId = msg.id._serialized;
        await client.sendResponseToEvent(myResponse, msgId);
    }
});

4. To edit an event message (or to cancel an event):

// client initialization...

client.on('message', async (msg) => {
    if (msg.type === 'event_creation') {
        const editedEvent = new Event(/* Provide edited values here */);
        await msg.editEvent(editedEvent);
    }
});

To try this PR by yourself you can run one of the following commands:

  • NPM
npm install github:alechkos/whatsapp-web.js#group-events
  • YARN
yarn add github:alechkos/whatsapp-web.js#group-events

How Has The PR Been Tested

Tested with a code provided in usage example.


Types of Changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix/feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • I have updated the usage example accordingly (example.js)
  • I have updated the documentation accordingly (index.d.ts)

@Halphas
Copy link

Halphas commented Oct 28, 2024

wow love it!

@Halphas
Copy link

Halphas commented Oct 28, 2024

The event edit is not getting and unique identifier? how is it mapping the new Event(....) to the one i want to edit?
like i would probably save some event_id and then later when editiing try to do something like getEventById(event_id) = new Event(...) but in this case we do not have an event id right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants