diff --git a/CHANGELOG.md b/CHANGELOG.md index be89d79de9..150a19b37f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 2.6.0 (2024-08-05) + +## Bug Fixes +- **deps:** update dependency @wppconnect-team/wppconnect to ^1.32.4 ([550ff5d](https://github.com/wppconnect-team/wppconnect-server/commit/550ff5d13f13d55585119b3f1dbba517ccddb8cc)) +- **deps:** update dependency @wppconnect-team/wppconnect to ^1.33.0 ([#1978](https://github.com/wppconnect-team/wppconnect-server/issues/1978)) ([fdc30a8](https://github.com/wppconnect-team/wppconnect-server/commit/fdc30a8af41ebc8d73493c9857b6ff48b8fa8ea3)) + +## Features + +-- Added login by code support ([#1959](https://github.com/wppconnect-team/wppconnect-server/issues/1959)) ([0e60d34](https://github.com/wppconnect-team/wppconnect-server/commit/0e60d343b0cfadb288f22a704dd63a2ea2733f8e)) + ## 2.5.2 (2024-06-24) ### Bug Fixes diff --git a/package.json b/package.json index e489c05ff7..8729ef1b7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wppconnect/server", - "version": "2.5.2", + "version": "2.6.0", "description": "Project designed to dynamically authenticate WhatsApp Web automation with multi-clients. Backend made in Nodejs (express, socketio), FrontEnd (ReactJS)", "main": "dist/index.js", "author": "kingaspx", @@ -28,8 +28,8 @@ "test": "jest" }, "dependencies": { - "@aws-sdk/client-s3": "^3.623.0", - "@wppconnect-team/wppconnect": "^1.32.4", + "@aws-sdk/client-s3": "^3.624.0", + "@wppconnect-team/wppconnect": "^1.33.0", "archiver": "^7.0.1", "axios": "^1.7.3", "bcrypt": "^5.1.1", @@ -44,7 +44,7 @@ "merge-deep": "^3.0.3", "moment": "^2.30.1", "multer": "^1.4.5-lts.1", - "qrcode": "^1.5.3", + "qrcode": "^1.5.4", "socket.io": "^4.7.5", "swagger-autogen": "^2.23.7", "swagger-ui-express": "^5.0.1", @@ -77,9 +77,9 @@ "@types/qrcode": "^1.5.5", "@types/swagger-ui-express": "^4.1.6", "@types/unzipper": "^0.10.9", - "@typescript-eslint/eslint-plugin": "^8.0.0", - "@typescript-eslint/parser": "^8.0.0", - "@typescript-eslint/typescript-estree": "^8.0.0", + "@typescript-eslint/eslint-plugin": "^8.0.1", + "@typescript-eslint/parser": "^8.0.1", + "@typescript-eslint/typescript-estree": "^8.0.1", "commitizen": "^4.3.0", "conventional-changelog-cli": "^5.0.0", "crypto-js": "^4.2.0", diff --git a/src/util/createSessionUtil.ts b/src/util/createSessionUtil.ts index c337a0defe..a08e97e455 100644 --- a/src/util/createSessionUtil.ts +++ b/src/util/createSessionUtil.ts @@ -49,9 +49,8 @@ export default class CreateSessionUtil { const myTokenStore = tokenStore.createTokenStory(client); const tokenData = await myTokenStore.getToken(session); - if (!tokenData) { - myTokenStore.setToken(session, {}); - } + // we need this to update phone in config every time session starts, so we can ask for code for it again. + myTokenStore.setToken(session, tokenData ?? {}); this.startChatWootClient(client); @@ -68,12 +67,22 @@ export default class CreateSessionUtil { req.serverOptions.createOptions, { session: session, + phoneNumber: client.config.phone ?? null, deviceName: - client.config?.deviceName || req.serverOptions.deviceName, + client.config.phone == undefined // bug when using phone code this shouldn't be passed (https://github.com/wppconnect-team/wppconnect-server/issues/1687#issuecomment-2099357874) + ? client.config?.deviceName || + req.serverOptions.deviceName || + 'WppConnect' + : undefined, poweredBy: - client.config?.poweredBy || - req.serverOptions.poweredBy || - 'WPPConnect-Server', + client.config.phone == undefined // bug when using phone code this shouldn't be passed (https://github.com/wppconnect-team/wppconnect-server/issues/1687#issuecomment-2099357874) + ? client.config?.poweredBy || + req.serverOptions.poweredBy || + 'WPPConnect-Server' + : undefined, + catchLinkCode: (code: string) => { + this.exportPhoneCode(req, client.config.phone, code, client, res); + }, catchQR: ( base64Qr: any, asciiQR: any, @@ -142,6 +151,42 @@ export default class CreateSessionUtil { await this.createSessionUtil(req, clientsArray, session, res); } + exportPhoneCode( + req: any, + phone: any, + phoneCode: any, + client: WhatsAppServer, + res?: any, + ) { + eventEmitter.emit(`phoneCode-${client.session}`, phoneCode, client); + + Object.assign(client, { + status: 'PHONECODE', + phoneCode: phoneCode, + phone: phone, + }); + + req.io.emit('phoneCode', { + data: phoneCode, + phone: phone, + session: client.session, + }); + + callWebHook(client, req, 'phoneCode', { + phoneCode: phoneCode, + phone: phone, + session: client.session, + }); + + if (res && !res._headerSent) + res.status(200).json({ + status: 'phoneCode', + phone: phone, + phoneCode: phoneCode, + session: client.session, + }); + } + exportQR( req: any, qrCode: any,