Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added WPP.chat.getVotes function #810

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/chat/functions/getVotes.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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