Skip to content

Commit

Permalink
feat: Added WPP.chat.getReactions function (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Dec 13, 2022
1 parent 5b05beb commit 422da5f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/chat/functions/getReactions.ts
@@ -0,0 +1,90 @@
/*!
* 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 { createWid } from '../../util';
import { MsgKey } from '../../whatsapp';
import { getReactions as GetReaction } from '../../whatsapp/functions';

/**
* Get all reactions in a message
* @example
* ```javascript
* WPP.chat.getReactions('true_[number]@c.us_ABCDEF');
* ```
* @category Chat
*/

export async function getReactions(msgId: string): Promise<{
reactionByMe: {
id: MsgKey;
orphan: number;
msgId: MsgKey;
reactionText: string;
read: boolean;
senderUserJid: string;
timestamp: number;
};
reactions: {
aggregateEmoji: string;
hasReactionByMe: boolean;
senders: {
id: MsgKey;
orphan: number;
msgId: MsgKey;
reactionText: string;
read: boolean;
senderUserJid: string;
timestamp: number;
}[];
}[];
}> {
const reactions = await GetReaction(msgId);

const returnData: any = [];
for (const d of reactions.reactions) {
const data = {
aggregateEmoji: d.aggregateEmoji,
hasReactionByMe: d.hasReactionByMe,
senders: <any>[],
};
for (const e of d.senders) {
data.senders.push({
id: e.msgKey as MsgKey,
msgId: e.parentMsgKey,
reactionText: e.reactionText,
read: e.read,
sender: createWid(e.senderUserJid)!,
orphan: e.orphan,
timestamp: e.timestamp,
});
}
returnData.push(data);
}
return {
reactionByMe: reactions.reactionByMe
? <any>{
id: reactions.reactionByMe.msgKey as MsgKey,
orphan: reactions.reactionByMe.orphan as number,
msgId: reactions.reactionByMe.parentMsgKey as MsgKey,
reactionText: reactions.reactionByMe.reactionText as string,
read: reactions.reactionByMe.read as boolean,
senderUserJid: createWid(reactions.reactionByMe.senderUserJid)!,
timestamp: reactions.reactionByMe.timestamp as number,
}
: undefined,
reactions: 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 { getReactions } from './getReactions';
export { getVotes } from './getVotes';
export { ChatListOptions, list } from './list';
export { markIsComposing } from './markIsComposing';
Expand Down
48 changes: 48 additions & 0 deletions src/whatsapp/functions/getReactions.ts
@@ -0,0 +1,48 @@
/*!
* 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';

/**
* @whatsapp 297673
* @whatsapp 297673 >= 2.2232.6
*/
export interface ReactionReturn {
reactionByMe: any;
reactions: {
aggregateEmoji: string;
hasReactionByMe: boolean;
senders: {
msgKey: MsgKey;
orphan: number;
parentMsgKey: MsgKey;
reactionText: string;
read: boolean;
senderUserJid: string;
timestamp: number;
}[];
}[];
}
export declare function getReactions(msgId: string): Promise<ReactionReturn>;

exportModule(
exports,
{
getReactions: 'getReactions',
},
(m) => m.getReactions
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -35,6 +35,7 @@ export * from './getFanOutList';
export * from './getGroupSenderKeyList';
export * from './getHistorySyncProgress';
export * from './getQuotedMsgObj';
export * from './getReactions';
export * from './getSearchContext';
export * from './getVotes';
export * from './groupParticipants';
Expand Down

0 comments on commit 422da5f

Please sign in to comment.