From a4f06f9bd95f2a79375350ed847a075e2df00550 Mon Sep 17 00:00:00 2001 From: Edgard Date: Fri, 3 Jun 2022 11:24:57 -0300 Subject: [PATCH] feat: Added WPP.conn.getMyDeviceId function (fix #433) --- src/conn/functions/getMyDeviceId.ts | 30 +++++++++++++++++++++++++++++ src/conn/functions/index.ts | 1 + 2 files changed, 31 insertions(+) create mode 100644 src/conn/functions/getMyDeviceId.ts diff --git a/src/conn/functions/getMyDeviceId.ts b/src/conn/functions/getMyDeviceId.ts new file mode 100644 index 0000000000..b7b3c77f26 --- /dev/null +++ b/src/conn/functions/getMyDeviceId.ts @@ -0,0 +1,30 @@ +/*! + * 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 { UserPrefs, Wid } from '../../whatsapp'; + +/** + * Return the current logged user ID with device id + * + * @example + * ```javascript + * const wid = WPP.conn.getMyDeviceId(); + * console.log(wid.toString()); // Output: 123:4@c.us + * ``` + */ +export function getMyDeviceId(): Wid | undefined { + return UserPrefs.getMe(); +} diff --git a/src/conn/functions/index.ts b/src/conn/functions/index.ts index 6343234b17..200430d620 100644 --- a/src/conn/functions/index.ts +++ b/src/conn/functions/index.ts @@ -15,6 +15,7 @@ */ export { getAuthCode } from './getAuthCode'; +export { getMyDeviceId } from './getMyDeviceId'; export { getMyUserId } from './getMyUserId'; export { isAuthenticated } from './isAuthenticated'; export { isIdle } from './isIdle';