Skip to content

Commit

Permalink
feat: Added WPP.chat.forwardMessage function (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 5, 2022
1 parent 9b50365 commit afe5ac3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/chat/functions/forwardMessage.ts
@@ -0,0 +1,51 @@
/*!
* Copyright 2021 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 { assertFindChat } from '../../assert';
import { MsgKey, Wid } from '../../whatsapp';
import { getMessageById, RawMessage } from '..';

export interface ForwardMessagesOptions {
displayCaptionText?: boolean;
multicast?: boolean;
}

/**
* Forward messages to a chat
*
* @example
* ```javascript
* // Forward messages
* WPP.chat.forwardMessage('[number]@c.us', 'true_[number]@c.us_ABCDEF');
* ```
* @category Message
* @return {any} Any
*/
export async function forwardMessage(
toChatId: string | Wid,
msgId: string | MsgKey,
options: ForwardMessagesOptions = {}
): Promise<RawMessage[]> {
const chat = await assertFindChat(toChatId);

const msg = await getMessageById(msgId);

return await chat.forwardMessages(
[msg],
options.multicast,
options.displayCaptionText
);
}
1 change: 1 addition & 0 deletions src/chat/functions/index.ts
Expand Up @@ -23,6 +23,7 @@ export { delete } from './delete';
export { deleteMessage, DeleteMessageReturn } from './deleteMessage';
export { downloadMedia } from './downloadMedia';
export { find } from './find';
export { forwardMessage, ForwardMessagesOptions } from './forwardMessage';
export { generateMessageID } from './generateMessageID';
export { get } from './get';
export { getLastSeen } from './getLastSeen';
Expand Down
8 changes: 6 additions & 2 deletions src/whatsapp/collections/ChatCollection.ts
Expand Up @@ -15,7 +15,7 @@
*/

import { exportModule } from '../exportModule';
import { ChatModel } from '../models';
import { ChatModel, MsgModel } from '../models';
import { BaseCollection } from './BaseCollection';

/** @whatsapp 69951
Expand All @@ -34,7 +34,11 @@ export declare class ChatCollection extends BaseCollection<ChatModel> {
getKeysForResyncMsgs(): any;
resyncMessages(): any;
unstarAllMessages(e?: any, t?: any): any;
forwardMessagesToChats(e?: any, t?: any): any;
forwardMessagesToChats(
msgs: MsgModel[],
chats: ChatModel[],
displayCaptionText?: boolean
): any;
}

exportModule(
Expand Down
6 changes: 5 additions & 1 deletion src/whatsapp/models/ChatModel.ts
Expand Up @@ -183,7 +183,11 @@ export declare class ChatModel extends ModelChatBase {
i?: any,
n?: any
): any;
forwardMessages(e?: any, t?: boolean): any;
forwardMessages(
msgs: MsgModel[],
multicast?: any,
displayCaptionText?: boolean
): any;
updateReadOnly(): any;
updateIsAnnounceGrpRestrict(): any;
sortMsgs(e?: any): any;
Expand Down

0 comments on commit afe5ac3

Please sign in to comment.