Skip to content

Commit

Permalink
feat: Added WPP.conn.genLinkDeviceCodeForPhoneNumber function (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 28, 2023
1 parent a7766fb commit 7e5d363
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/conn/functions/genLinkDeviceCodeForPhoneNumber.ts
@@ -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
);
}
1 change: 1 addition & 0 deletions src/conn/functions/index.ts
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

export { genLinkDeviceCodeForPhoneNumber } from './genLinkDeviceCodeForPhoneNumber';
export { getAuthCode } from './getAuthCode';
export {
getHistorySyncProgress,
Expand Down
33 changes: 33 additions & 0 deletions src/whatsapp/functions/genLinkDeviceCodeForPhoneNumber.ts
@@ -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
);
2 changes: 2 additions & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -44,6 +44,7 @@ export * from './findCommonGroups';
export * from './findFirstWebLink';
export * from './frontendFireAndForget';
export * from './generateVideoThumbsAndDuration';
export * from './genLinkDeviceCodeForPhoneNumber';
export * from './genMinimalLinkPreview';
export * from './getABPropConfigValue';
export * from './getAsMms';
Expand All @@ -67,6 +68,7 @@ export * from './getWhatsAppWebExternalBetaJoinedIdb';
export * from './groupParticipants';
export * from './handleAck';
export * from './handleSingleMsg';
export * from './initializeAltDeviceLinking';
export * from './isAnimatedWebp';
export * from './isAuthenticated';
export * from './isRegistered';
Expand Down
30 changes: 30 additions & 0 deletions src/whatsapp/functions/initializeAltDeviceLinking.ts
@@ -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
);

0 comments on commit 7e5d363

Please sign in to comment.