Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added WPP.conn.setLimit function (#1069)
Co-authored-by: Edgard Lorraine Messias <edgardmessias@gmail.com>
- Loading branch information
1 parent
9708d49
commit 9988fc7
Showing
11 changed files
with
306 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*! | ||
* 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 { wrapModuleFunction } from '../../whatsapp/exportModule'; | ||
import { WPPError } from '../../util'; | ||
import { ServerProps } from '../../whatsapp'; | ||
import { getNumChatsPinned } from '../../whatsapp/functions'; | ||
import * as webpack from '../../webpack'; | ||
|
||
/** | ||
* Change limits | ||
* | ||
* @example | ||
* ```javascript | ||
* //Change the maximum size (bytes) for uploading media (max 70MB) | ||
* WPP.conn.setLimit('maxMediaSize',16777216); | ||
* | ||
* //Change the maximum size (bytes) for uploading files (max 1GB) | ||
* WPP.conn.setLimit('maxFileSize',104857600); | ||
* | ||
* //Change the maximum number of contacts that can be selected when sharing (Default 5) | ||
* WPP.conn.setLimit('maxShare',100); | ||
* | ||
* //Change the maximum time (seconds) of a video status | ||
* WPP.conn.setLimit('statusVideoMaxDuration',120); | ||
* | ||
* //Remove pinned conversation limit (only whatsapp web) (Default 3) | ||
* WPP.conn.setLimit('unlimitedPin',true); | ||
* ``` | ||
*/ | ||
|
||
let unlimitedPin: undefined | boolean = undefined; | ||
|
||
webpack.onInjected(() => { | ||
|
||
wrapModuleFunction(getNumChatsPinned, (func,...args) => { | ||
const getNumChatsPinnedOriginal = func(...args); | ||
return unlimitedPin ? 1 : getNumChatsPinnedOriginal | ||
}); | ||
|
||
}); | ||
|
||
export function setLimit(key: string, value: boolean | number): any { | ||
switch (key) { | ||
|
||
case "maxMediaSize": { | ||
if (typeof value !== 'number' || value > 73400320) { | ||
throw new WPPError( | ||
`maxMediaSize_error`, | ||
typeof value !== 'number' ? `Value type invalid!` : `Maximum value is 70MB` | ||
); | ||
} | ||
ServerProps.media = value; | ||
return ServerProps.media; | ||
} | ||
|
||
case "maxFileSize": { | ||
if (typeof value !== 'number' || (value > 1073741824)) { | ||
throw new WPPError( | ||
`maxFileSize_error`, | ||
typeof value !== 'number' ? `Value type invalid!`: `Maximum value is 1GB` | ||
); | ||
} | ||
ServerProps.maxFileSize = value | ||
return ServerProps.maxFileSize | ||
} | ||
|
||
case "maxShare": { | ||
if (typeof value !== 'number') { | ||
throw new WPPError( | ||
`maxShare_error`, | ||
`Value type invalid!` | ||
); | ||
} | ||
ServerProps.multicastLimitGlobal = value; | ||
ServerProps.frequentlyForwardedMax = value; | ||
ServerProps.frequentlyForwardedThreshold = value; | ||
return ServerProps.multicastLimitGlobal; | ||
} | ||
|
||
case "statusVideoMaxDuration": { | ||
if (typeof value !== 'number') { | ||
throw new WPPError( | ||
`statusVideoMaxDuration_error`, | ||
`Value type invalid!` | ||
); | ||
} | ||
ServerProps.statusVideoMaxDuration = value; | ||
return ServerProps.statusVideoMaxDuration; | ||
} | ||
|
||
case "unlimitedPin": { | ||
if (typeof value !== 'boolean') { | ||
throw new WPPError( | ||
`unlimitedPin_error`, | ||
`Value type invalid!` | ||
); | ||
} | ||
value ? unlimitedPin = value : unlimitedPin = undefined; | ||
return value | ||
} | ||
|
||
default: { | ||
throw new WPPError( | ||
`setLimit_error`, | ||
`Key type invalid!` | ||
); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! | ||
* 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 { exportModule } from '../exportModule'; | ||
|
||
/** | ||
* @whatsapp 95547 | ||
* @whatsapp 695547 >= 2.2222.8 | ||
* @whatsapp 925080 >= 2.2228.4 | ||
*/ | ||
|
||
export declare function getABPropConfigValue(value: any): any; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
getABPropConfigValue: 'getABPropConfigValue', | ||
}, | ||
(m) => m.getABPropConfigValue | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! | ||
* 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 { exportModule } from '../exportModule'; | ||
|
||
/** | ||
* @whatsapp 95547 | ||
* @whatsapp 695547 >= 2.2222.8 | ||
* @whatsapp 925080 >= 2.2228.4 | ||
*/ | ||
export declare function getNumChatsPinned(value: any): any; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
getNumChatsPinned: 'getNumChatsPinned', | ||
}, | ||
(m) => m.getNumChatsPinned | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*! | ||
* 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 { exportModule } from '../exportModule'; | ||
import { ServerPropsModel } from '../models'; | ||
|
||
/** @whatsapp 8080 | ||
* @whatsapp 608080 >= 2.2222.8 | ||
*/ | ||
export declare const ServerProps: ServerPropsModel | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
ServerProps: 'ServerProps', | ||
}, | ||
(m) => m.getMaxFilesSizeServerProp && m.ServerProps | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*! | ||
* 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 { exportModule } from '../exportModule'; | ||
import { | ||
Model, | ||
ModelOptions, | ||
ModelPropertiesContructor, | ||
ModelProxy, | ||
} from './Model'; | ||
|
||
interface Props { | ||
statusVideoMaxDuration: number; | ||
multicastLimitGlobal: number; | ||
frequentlyForwardedThreshold: number; | ||
frequentlyForwardedMax: number; | ||
maxFileSize: number; | ||
media: number; | ||
} | ||
|
||
interface Session { | ||
} | ||
|
||
interface Derived { | ||
} | ||
|
||
/** @whatsapp 17239 | ||
* @whatsapp 317239 >= 2.2222.8 | ||
*/ | ||
export declare interface ServerPropsModel | ||
extends ModelProxy<Props, Session, Derived> {} | ||
|
||
/** @whatsapp 17239 | ||
* @whatsapp 317239 >= 2.2222.8 | ||
*/ | ||
export declare class ServerPropsModel extends Model { | ||
constructor( | ||
proterties?: ModelPropertiesContructor<ServerPropsModel>, | ||
options?: ModelOptions | ||
); | ||
} | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
ServerPropsModel: 'ServerProps', | ||
}, | ||
(m) => m.getMaxFilesSizeServerProp && m.ServerProps | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters