From 5b05beb3f5bd2ab85fa559e200f5a96e9627218e Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Tue, 13 Dec 2022 08:20:43 -0300 Subject: [PATCH] feat: Added WPP.chat.getVotes function (#810) --- src/chat/functions/getVotes.ts | 59 ++++++++++++++++++++++++++++++ src/chat/functions/index.ts | 1 + src/whatsapp/functions/getVotes.ts | 34 +++++++++++++++++ src/whatsapp/functions/index.ts | 1 + 4 files changed, 95 insertions(+) create mode 100644 src/chat/functions/getVotes.ts create mode 100644 src/whatsapp/functions/getVotes.ts diff --git a/src/chat/functions/getVotes.ts b/src/chat/functions/getVotes.ts new file mode 100644 index 0000000000..264f5e1bd9 --- /dev/null +++ b/src/chat/functions/getVotes.ts @@ -0,0 +1,59 @@ +/*! + * Copyright 2022 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MsgKey, Wid } from '../../whatsapp'; +import { getVotes as GetVotes } from '../../whatsapp/functions'; + +/** + * Get votes of a poll + * @example + * ```javascript + * WPP.chat.getVotes('true_[number]@c.us_ABCDEF'); + * ``` + * @category Chat + */ +export async function getVotes(id: string | MsgKey): Promise<{ + msgId: MsgKey; + chatId: Wid; + votes: { + selectedOptions: number[]; + timestamp: number; + sender: Wid; + }[]; +}> { + const msgKey = MsgKey.fromString(id.toString()); + + const votes = await GetVotes(msgKey); + const returnData = { + msgId: msgKey, + chatId: msgKey.remote, + votes: < + { + selectedOptions: number[]; + timestamp: number; + sender: Wid; + }[] + >[], + }; + for (const vote of votes) { + returnData.votes.push({ + selectedOptions: vote.selectedOptionLocalIds, + timestamp: vote.senderTimestampMs, + sender: vote.sender, + }); + } + return returnData; +} diff --git a/src/chat/functions/index.ts b/src/chat/functions/index.ts index a14b7964a6..266419ce85 100644 --- a/src/chat/functions/index.ts +++ b/src/chat/functions/index.ts @@ -32,6 +32,7 @@ export { getMessageACK } from './getMessageACK'; export { getMessageById } from './getMessageById'; export { getMessages, GetMessagesOptions } from './getMessages'; export { getPlatformFromMessage } from './getPlatformFromMessage'; +export { getVotes } from './getVotes'; export { ChatListOptions, list } from './list'; export { markIsComposing } from './markIsComposing'; export { markIsPaused } from './markIsPaused'; diff --git a/src/whatsapp/functions/getVotes.ts b/src/whatsapp/functions/getVotes.ts new file mode 100644 index 0000000000..3f8c3e0b52 --- /dev/null +++ b/src/whatsapp/functions/getVotes.ts @@ -0,0 +1,34 @@ +/*! + * Copyright 2022 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { exportModule } from '../exportModule'; +import { MsgKey } from '../misc'; +import { VoteData } from './upsertVotes'; + +/** + * @whatsapp 816349 + * @whatsapp 816349 >= 2.2232.6 + */ +export declare function getVotes(id: MsgKey): Promise; + +exportModule( + exports, + { + getVotes: 'getVotes', + getVote: 'getVote', + }, + (m) => m.getVotes && m.getVote +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index 89decd43fd..e4d16c5228 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -36,6 +36,7 @@ export * from './getGroupSenderKeyList'; export * from './getHistorySyncProgress'; export * from './getQuotedMsgObj'; export * from './getSearchContext'; +export * from './getVotes'; export * from './groupParticipants'; export * from './handleAck'; export * from './isAnimatedWebp';