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:
parent
ab321f3d7e
commit
f9db14d185
1 changed files with 261 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ const Order = require('./Order');
|
|||
const Payment = require('./Payment');
|
||||
const Reaction = require('./Reaction');
|
||||
const Contact = require('./Contact');
|
||||
const ScheduledEvent = require('./ScheduledEvent'); // eslint-disable-line no-unused-vars
|
||||
const { MessageTypes } = require('../util/Constants');
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +52,7 @@ class Message extends Base {
|
|||
* Message content
|
||||
* @type {string}
|
||||
*/
|
||||
this.body = this.hasMedia ? data.caption || '' : data.body || data.pollName || '';
|
||||
this.body = this.hasMedia ? data.caption || '' : data.body || data.pollName || data.eventName || '';
|
||||
|
||||
/**
|
||||
* Message type
|
||||
|
|
@ -699,6 +700,40 @@ class Message extends Base {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the current ScheduledEvent message.
|
||||
* Once the scheduled event is canceled, it can not be edited.
|
||||
* @param {ScheduledEvent} editedEventObject
|
||||
* @returns {Promise<?Message>}
|
||||
*/
|
||||
async editScheduledEvent(editedEventObject) {
|
||||
if (!this.fromMe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const edittedEventMsg = await this.client.pupPage.evaluate(async (msgId, editedEventObject) => {
|
||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
if (!msg) return null;
|
||||
|
||||
const { name, startTimeTs, eventSendOptions } = editedEventObject;
|
||||
const eventOptions = {
|
||||
name: name,
|
||||
description: eventSendOptions.description,
|
||||
startTime: startTimeTs,
|
||||
endTime: eventSendOptions.endTimeTs,
|
||||
location: eventSendOptions.location,
|
||||
callType: eventSendOptions.callType,
|
||||
isEventCanceled: eventSendOptions.isEventCanceled,
|
||||
};
|
||||
|
||||
await window.Store.ScheduledEventMsgUtils.sendEventEditMessage(eventOptions, msg);
|
||||
const editedMsg = window.Store.Msg.get(msg.id._serialized);
|
||||
return editedMsg?.serialize();
|
||||
}, this.id._serialized, editedEventObject);
|
||||
|
||||
return edittedEventMsg && new Message(this.client, edittedEventMsg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message;
|
||||
|
|
|
|||
Loading…
Reference in a new issue