Skip to content

Commit

Permalink
feat: Added WPP.chat.getVotes function (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Dec 13, 2022
1 parent 428dfa8 commit 5b05beb
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
59 changes: 59 additions & 0 deletions 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;
}
1 change: 1 addition & 0 deletions src/chat/functions/index.ts
Expand Up @@ -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';
Expand Down
34 changes: 34 additions & 0 deletions 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<VoteData[]>;

exportModule(
exports,
{
getVotes: 'getVotes',
getVote: 'getVote',
},
(m) => m.getVotes && m.getVote
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -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';
Expand Down

0 comments on commit 5b05beb

Please sign in to comment.