Poll implementation

This commit is contained in:
purpshell
2022-12-23 12:37:07 +02:00
parent 288a572af6
commit a519105870
6 changed files with 184 additions and 49 deletions

24
index.d.ts vendored
View File

@@ -2,6 +2,7 @@
import { EventEmitter } from 'events'
import { RequestInit } from 'node-fetch'
import * as puppeteer from 'puppeteer'
import PollVote from './src/structures/PollVote'
declare namespace WAWebJS {
@@ -268,6 +269,12 @@ declare namespace WAWebJS {
/** Emitted when the RemoteAuth session is saved successfully on the external Database */
on(event: 'remote_session_saved', listener: () => void): this
/** Emitted when a poll vote is received */
on(event: 'poll_vote', listener: (
/** The poll vote */
vote: PollVote
) => void): this
}
/** Current connection information */
@@ -506,7 +513,8 @@ declare namespace WAWebJS {
DISCONNECTED = 'disconnected',
STATE_CHANGED = 'change_state',
BATTERY_CHANGED = 'change_battery',
REMOTE_SESSION_SAVED = 'remote_session_saved'
REMOTE_SESSION_SAVED = 'remote_session_saved',
POLL_VOTE = 'poll_vote'
}
/** Group notification types */
@@ -569,6 +577,7 @@ declare namespace WAWebJS {
PROTOCOL = 'protocol',
REACTION = 'reaction',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
POLL_CREATION = 'poll_creation',
}
/** Client status */
@@ -721,6 +730,10 @@ declare namespace WAWebJS {
selectedRowId?: string,
/** Returns message in a raw format */
rawData: object,
/** Avaiaible poll voting options */
pollOptions: string[],
/** The current poll votes, refresh with .refreshPollVotes() */
pollVotes: PollVote[],
/*
* 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.
@@ -766,6 +779,15 @@ declare namespace WAWebJS {
* Gets the payment details associated with a given message
*/
getPayment: () => Promise<Payment>,
/**
* Refreshes the current poll votes, only works with a poll_creation message
*/
refreshPollVotes: () => Promise<void>,
/**
* Vote on the poll, only works with a poll_creation message
* @param {Array<string>} selectedOptions The selected options from .pollOptions
*/
vote: (selectedOptions: string[]) => Promise<void>,
}
/** ID that represents a message */