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.genLinkDeviceCodeForPhoneNumber function (close #…
- Loading branch information
1 parent
a7766fb
commit 7e5d363
Showing
5 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*! | ||
* 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 { WPPError } from '../../util'; | ||
import { functions } from '../../whatsapp'; | ||
import { isAuthenticated } from '.'; | ||
|
||
/** | ||
* Alternative login method using code | ||
* Get the Link Device Code for Authentication using the phone number | ||
* | ||
* @example | ||
* ```javascript | ||
* const code = await WPP.conn.genLinkDeviceCodeForPhoneNumber('[number]'); | ||
* | ||
* // Disable push notification | ||
* const code = await WPP.conn.genLinkDeviceCodeForPhoneNumber('[number]', false); | ||
* ``` | ||
* | ||
* @category Conn | ||
*/ | ||
export async function genLinkDeviceCodeForPhoneNumber( | ||
phone: string, | ||
sendPushNotification = true | ||
): Promise<string> { | ||
if (isAuthenticated()) { | ||
throw new WPPError( | ||
'cannot_get_code_for_already_authenticated', | ||
"Can't get code for already authenticated user" | ||
); | ||
} | ||
|
||
await functions.initializeAltDeviceLinking(); | ||
|
||
return await functions.genLinkDeviceCodeForPhoneNumber( | ||
phone, | ||
sendPushNotification | ||
); | ||
} |
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 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'; | ||
|
||
/** | ||
* @whatsapp 61777 | ||
*/ | ||
export declare function genLinkDeviceCodeForPhoneNumber( | ||
phone: string, | ||
pushNotification: boolean | ||
): Promise<string>; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
genLinkDeviceCodeForPhoneNumber: 'genLinkDeviceCodeForPhoneNumber', | ||
}, | ||
(m) => m.genLinkDeviceCodeForPhoneNumber | ||
); |
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,30 @@ | ||
/*! | ||
* 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'; | ||
|
||
/** | ||
* @whatsapp 518043 | ||
*/ | ||
export declare function initializeAltDeviceLinking(): Promise<void>; | ||
|
||
exportModule( | ||
exports, | ||
{ | ||
initializeAltDeviceLinking: 'initializeAltDeviceLinking', | ||
}, | ||
(m) => m.initializeAltDeviceLinking | ||
); |