Skip to content

Commit

Permalink
feat: Added WPP.chat.requestPhoneNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 19, 2022
1 parent 85cac99 commit 4723eac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chat/functions/index.ts
Expand Up @@ -50,6 +50,7 @@ export {
prepareMessageButtons,
} from './prepareMessageButtons';
export { prepareRawMessage } from './prepareRawMessage';
export { requestPhoneNumber } from './requestPhoneNumber';
export {
PoolMessageOptions,
sendCreatePollMessage,
Expand Down
61 changes: 61 additions & 0 deletions src/chat/functions/requestPhoneNumber.ts
@@ -0,0 +1,61 @@
/*!
* Copyright 2022 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 { assertWid } from '../../assert';
import { WPPError } from '../../util';
import {
defaultSendMessageOptions,
RawMessage,
SendMessageOptions,
SendMessageReturn,
} from '..';
import { sendRawMessage } from '.';

/**
* Request the real phone number for a LID chat ([number]@lid)
*
* @example
* ```javascript
* // Request
* WPP.chat.requestPhoneNumber('[number]@lid');
* ```
*
* @category Message
*/
export async function requestPhoneNumber(
chatId: any,
options: SendMessageOptions = {}
): Promise<SendMessageReturn> {
options = {
...defaultSendMessageOptions,
...options,
};

const wid = assertWid(chatId);

if (!wid.isLid()) {
throw new WPPError(
'not_a_lid_chat',
`requestPhoneNumber should not be called for non lid chat ${wid.toString()}`
);
}

const rawMessage: RawMessage = {
type: 'request_phone_number',
};

return await sendRawMessage(chatId, rawMessage, options);
}

0 comments on commit 4723eac

Please sign in to comment.