Get Stories (#3294)

* Get all broadcast

* fixed return msgs

* feat: add usage example

* Update src/structures/Broadcast.js

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
tofers 2024-09-30 20:33:31 +03:00 • committed by GitHub
commit 5b0e139ad4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 125 additions and 2 deletions

View file

@ -0,0 +1,69 @@
'use strict';
const Base = require('./Base');
const Message = require('./Message');
/**
* Represents a Status/Story on WhatsApp
* @extends {Base}
*/
class Broadcast extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
/**
* ID that represents the chat
* @type {object}
*/
this.id = data.id;
/**
* Unix timestamp of last status
* @type {number}
*/
this.timestamp = data.t;
/**
* Number of available statuses
* @type {number}
*/
this.totalCount = data.totalCount;
/**
* Number of not viewed
* @type {number}
*/
this.unreadCount = data.unreadCount;
/**
* Messages statuses
* @type {Message[]}
*/
this.msgs = data.msgs.map(msg => new Message(this.client, msg));
return super._patch(data);
}
/**
* Returns the Chat this message was sent in
* @returns {Promise<Chat>}
*/
getChat() {
return this.client.getChatById(this.id._serialized);
}
/**
* Returns the Contact this message was sent from
* @returns {Promise<Contact>}
*/
getContact() {
return this.client.getContactById(this.id._serialized);
}
}
module.exports = Broadcast;

View file

@ -20,5 +20,6 @@ module.exports = {
Payment: require('./Payment'),
Reaction: require('./Reaction'),
Poll: require('./Poll'),
PollVote: require('./PollVote')
PollVote: require('./PollVote'),
Broadcast: require('./Broadcast')
};