diff --git a/src/chat/functions/getReactions.ts b/src/chat/functions/getReactions.ts new file mode 100644 index 0000000000..7735cc5493 --- /dev/null +++ b/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: [], + }; + 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 + ? { + 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, + }; +} diff --git a/src/chat/functions/index.ts b/src/chat/functions/index.ts index 266419ce85..4237d0ca86 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 { getReactions } from './getReactions'; export { getVotes } from './getVotes'; export { ChatListOptions, list } from './list'; export { markIsComposing } from './markIsComposing'; diff --git a/src/whatsapp/functions/getReactions.ts b/src/whatsapp/functions/getReactions.ts new file mode 100644 index 0000000000..ff09f2583a --- /dev/null +++ b/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; + +exportModule( + exports, + { + getReactions: 'getReactions', + }, + (m) => m.getReactions +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index e4d16c5228..c184573292 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -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';