Skip to content

Commit

Permalink
feat: Added support to reject call for WhatsApp >= 2.2301.5
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jan 20, 2023
1 parent 3b5a323 commit 2aaf02c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 18 deletions.
40 changes: 25 additions & 15 deletions src/call/functions/rejectCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/

import { WPPError } from '../../util';
import { CallModel, CallStore } from '../../whatsapp';
import { CallModel, CallStore, UserPrefs, websocket } from '../../whatsapp';
import { CALL_STATES } from '../../whatsapp/enums';
import { sendCallSignalingMsg } from '../../whatsapp/functions';

/**
* Reject a incoming call
Expand Down Expand Up @@ -72,20 +71,31 @@ export async function rejectCall(callId?: string): Promise<boolean> {
);
}

await sendCallSignalingMsg({
common: {
peer_jid: call.peerJid.toString(),
if (!call.peerJid.isGroupCall()) {
await websocket.ensureE2ESessions([call.peerJid]);
}

const node = websocket.smax(
'call',
{
from: UserPrefs.getMaybeMeUser().toString({ legacy: true }),
to: call.peerJid.toString({ legacy: true }),
id: websocket.generateId(),
},
payload: [
'reject',
{
'call-id': call.id,
'call-creator': call.peerJid.toString({ legacy: true }),
count: '0',
},
null,
],
});
[
websocket.smax(
'reject',
{
'call-id': call.id,
'call-creator': call.peerJid.toString({ legacy: true }),
count: '0',
},
null
),
]
);

await websocket.sendSmaxStanza(node);

return true;
}
2 changes: 1 addition & 1 deletion src/whatsapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export * from './misc';
export * from './models';
export * as multidevice from './multidevice';
export * from './stores';
export * from './websocket';
export * as websocket from './websocket';
31 changes: 31 additions & 0 deletions src/whatsapp/websocket/ensureE2ESessions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Copyright 2023 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 { Wid } from '../misc';

/**
* @whatsapp 917504 >= 2.2301.6
*/
export declare function ensureE2ESessions(wid: Wid[]): Promise<any>;

exportModule(
exports,
{
ensureE2ESessions: 'ensureE2ESessions',
},
(m) => m.ensureE2ESessions
);
2 changes: 2 additions & 0 deletions src/whatsapp/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

export * from './ensureE2ESessions';
export * from './generateId';
export * from './sendSmaxStanza';
export * from './smax';
export * from './wap';
export * from './WapNode';
34 changes: 34 additions & 0 deletions src/whatsapp/websocket/sendSmaxStanza.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Copyright 2023 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 { WapNode } from './';

/**
* @whatsapp 67201 >= 2.2301.6
*/
export declare function sendSmaxStanza(
node: WapNode,
options?: any
): Promise<WapNode>;

exportModule(
exports,
{
sendSmaxStanza: 'sendSmaxStanza',
},
(m) => m.sendSmaxStanza
);
2 changes: 1 addition & 1 deletion src/whatsapp/websocket/smax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { WapNode } from './WapNode';
export declare function smax(
tag: any,
attrs?: { [key: string]: any },
content?: any[] | string
content?: any[] | string | null | ArrayBuffer | Uint8Array
): WapNode;

exportModule(
Expand Down
2 changes: 1 addition & 1 deletion src/whatsapp/websocket/wap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { WapNode } from './WapNode';
export declare function wap(
tag: any,
attrs?: { [key: string]: any },
content?: any[] | string
content?: any[] | string | null | ArrayBuffer | Uint8Array
): WapNode;

exportModule(
Expand Down

0 comments on commit 2aaf02c

Please sign in to comment.