Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added WPP.chat.getVotes function (#810)
- Loading branch information
1 parent
428dfa8
commit 5b05beb
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters