From cb0688c2573e2898bb7b87263a35483d8ed4684e Mon Sep 17 00:00:00 2001 From: icleitoncosta Date: Tue, 26 Sep 2023 20:03:50 -0300 Subject: [PATCH 1/5] feat: Added WPP.chat.sendScheduledCallMessage --- src/chat/functions/index.ts | 1 + .../functions/sendScheduledCallMessage.ts | 98 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/chat/functions/sendScheduledCallMessage.ts diff --git a/src/chat/functions/index.ts b/src/chat/functions/index.ts index 01510da6d2..bba4a2e69d 100644 --- a/src/chat/functions/index.ts +++ b/src/chat/functions/index.ts @@ -78,6 +78,7 @@ export { export { sendOrderMessage } from './sendOrderMessage'; export { sendRawMessage } from './sendRawMessage'; export { sendReactionToMessage } from './sendReactionToMessage'; +export { sendScheduledCallMessage } from './sendScheduledCallMessage'; export { sendTextMessage, TextMessageOptions } from './sendTextMessage'; export { sendVCardContactMessage, diff --git a/src/chat/functions/sendScheduledCallMessage.ts b/src/chat/functions/sendScheduledCallMessage.ts new file mode 100644 index 0000000000..e9904b3715 --- /dev/null +++ b/src/chat/functions/sendScheduledCallMessage.ts @@ -0,0 +1,98 @@ +/*! + * 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 * as webpack from '../../webpack'; +import { wrapModuleFunction } from '../../whatsapp/exportModule'; +import { + createMsgProtobuf, + typeAttributeFromProtobuf, +} from '../../whatsapp/functions'; +import { + defaultSendMessageOptions, + RawMessage, + SendMessageOptions, + SendMessageReturn, +} from '..'; +import { sendRawMessage } from '.'; + +export enum SCHEDULED_CALL_TYPE { + UNKNOWN = 0, + VOICE = 1, + VIDEO = 2, +} + +export interface ScheduledCallMessageOptions extends SendMessageOptions { + scheduledTimestampMs: number | string; + callType: string | SCHEDULED_CALL_TYPE; + title: string; +} + +/** + * Send a scheduled call message + * + * @example + * ```javascript + * WPP.chat.sendScheduledCallMessage('[number]@c.us', { + * title: "Title of event" + * callType: 'voice' + * scheduledTimestampMs: 1696084222000 + * }); + * ``` + * @category Message + */ +export async function sendScheduledCallMessage( + chatId: any, + options: ScheduledCallMessageOptions +): Promise { + options = { + ...defaultSendMessageOptions, + ...options, + }; + + if (typeof options.callType === 'string') { + options.callType = options.callType == 'voice' ? 1 : 2; + } + const rawMessage: RawMessage = { + type: 'scheduled_call', + title: options.title, + callType: options.callType, + scheduledTimestampMs: options.scheduledTimestampMs, + }; + + return await sendRawMessage(chatId, rawMessage, options); +} + +webpack.onReady(() => { + wrapModuleFunction(createMsgProtobuf, (func, ...args) => { + const [message] = args; + const r = func(...args); + if (message?.type == 'scheduled_call') { + r.scheduledCallCreationMessage = { + title: message.title, + scheduledTimestampMs: (message as any).scheduledTimestampMs, + callType: (message as any).callType, + }; + } + return r; + }); + wrapModuleFunction(typeAttributeFromProtobuf, (func, ...args) => { + const [proto] = args; + if (proto.scheduledCallCreationMessage) { + return 'text'; + } + return func(...args); + }); +}); From 59813179c2e7299b60727876323f86ea952f0d92 Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Wed, 27 Sep 2023 13:13:39 -0300 Subject: [PATCH 2/5] fix: Fixed type Co-authored-by: Edgard Lorraine Messias --- src/chat/functions/sendScheduledCallMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chat/functions/sendScheduledCallMessage.ts b/src/chat/functions/sendScheduledCallMessage.ts index e9904b3715..04d3afe8b4 100644 --- a/src/chat/functions/sendScheduledCallMessage.ts +++ b/src/chat/functions/sendScheduledCallMessage.ts @@ -36,7 +36,7 @@ export enum SCHEDULED_CALL_TYPE { export interface ScheduledCallMessageOptions extends SendMessageOptions { scheduledTimestampMs: number | string; - callType: string | SCHEDULED_CALL_TYPE; + callType: "video" | "voice" | SCHEDULED_CALL_TYPE; title: string; } From 4111d6a1504f1716f0fd5d5988ff9b8a00fb59ee Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Wed, 27 Sep 2023 13:13:54 -0300 Subject: [PATCH 3/5] fix: Fixed onFullReady function Co-authored-by: Edgard Lorraine Messias --- src/chat/functions/sendScheduledCallMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chat/functions/sendScheduledCallMessage.ts b/src/chat/functions/sendScheduledCallMessage.ts index 04d3afe8b4..dba6207bc7 100644 --- a/src/chat/functions/sendScheduledCallMessage.ts +++ b/src/chat/functions/sendScheduledCallMessage.ts @@ -75,7 +75,7 @@ export async function sendScheduledCallMessage( return await sendRawMessage(chatId, rawMessage, options); } -webpack.onReady(() => { +webpack.onFullReady(() => { wrapModuleFunction(createMsgProtobuf, (func, ...args) => { const [message] = args; const r = func(...args); From 3b84dfadad1d1eda47df938594758f1ee30ecbd2 Mon Sep 17 00:00:00 2001 From: Cleiton Carvalho Date: Wed, 27 Sep 2023 13:14:23 -0300 Subject: [PATCH 4/5] fix: Added default value Co-authored-by: Edgard Lorraine Messias --- src/chat/functions/sendScheduledCallMessage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chat/functions/sendScheduledCallMessage.ts b/src/chat/functions/sendScheduledCallMessage.ts index dba6207bc7..8ca444c7d3 100644 --- a/src/chat/functions/sendScheduledCallMessage.ts +++ b/src/chat/functions/sendScheduledCallMessage.ts @@ -58,6 +58,7 @@ export async function sendScheduledCallMessage( options: ScheduledCallMessageOptions ): Promise { options = { + callType: SCHEDULED_CALL_TYPE.VOICE, ...defaultSendMessageOptions, ...options, }; From df6c523e91c634a034c4d3770659d47afe5d11f4 Mon Sep 17 00:00:00 2001 From: icleitoncosta Date: Wed, 27 Sep 2023 13:26:21 -0300 Subject: [PATCH 5/5] fix: Fixed reviews --- src/chat/functions/sendScheduledCallMessage.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chat/functions/sendScheduledCallMessage.ts b/src/chat/functions/sendScheduledCallMessage.ts index 8ca444c7d3..abc039704c 100644 --- a/src/chat/functions/sendScheduledCallMessage.ts +++ b/src/chat/functions/sendScheduledCallMessage.ts @@ -36,7 +36,7 @@ export enum SCHEDULED_CALL_TYPE { export interface ScheduledCallMessageOptions extends SendMessageOptions { scheduledTimestampMs: number | string; - callType: "video" | "voice" | SCHEDULED_CALL_TYPE; + callType: 'video' | 'voice' | SCHEDULED_CALL_TYPE; title: string; } @@ -58,7 +58,7 @@ export async function sendScheduledCallMessage( options: ScheduledCallMessageOptions ): Promise { options = { - callType: SCHEDULED_CALL_TYPE.VOICE, + ...{ callType: SCHEDULED_CALL_TYPE.VOICE }, ...defaultSendMessageOptions, ...options, }; @@ -70,7 +70,7 @@ export async function sendScheduledCallMessage( type: 'scheduled_call', title: options.title, callType: options.callType, - scheduledTimestampMs: options.scheduledTimestampMs, + scheduledTimestampMs: parseInt(options.scheduledTimestampMs?.toString()), }; return await sendRawMessage(chatId, rawMessage, options);