From c1d1e73e2b3c571bd32f58af2a2ab8f78508260f Mon Sep 17 00:00:00 2001 From: SuperChang Date: Fri, 15 Nov 2024 14:31:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20parse=20room=20dynami?= =?UTF-8?q?c=20qrcode=20and=20join=20room=20by=20this=20qrcode=20(#79)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: :sparkles: add parse room dynamic qrcode and join room by this qrcode * 1.0.102 * fix: :bug: update grpc version * fix: :bug: typo --- package.json | 6 ++--- src/client/puppet-service.ts | 37 +++++++++++++++++++++++++++ src/server/puppet-implementation.ts | 39 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2cd8183a..4fc406d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@juzi/wechaty-puppet-service", - "version": "1.0.101", + "version": "1.0.102", "description": "Puppet Service for Wechaty", "type": "module", "exports": { @@ -51,7 +51,7 @@ "@chatie/eslint-config": "^1.0.4", "@chatie/semver": "^0.4.7", "@chatie/tsconfig": "^4.6.3", - "@juzi/wechaty-puppet": "^1.0.92", + "@juzi/wechaty-puppet": "^1.0.93", "@juzi/wechaty-puppet-mock": "^1.0.1", "@swc/core": "1.3.39", "@types/google-protobuf": "^3.15.5", @@ -73,7 +73,7 @@ "@juzi/wechaty-puppet": "^1.0.84" }, "dependencies": { - "@juzi/wechaty-grpc": "^1.0.87", + "@juzi/wechaty-grpc": "^1.0.89", "clone-class": "^1.1.1", "ducks": "^1.0.2", "file-box": "^1.5.5", diff --git a/src/client/puppet-service.ts b/src/client/puppet-service.ts index d9e52d31..cd4b470c 100644 --- a/src/client/puppet-service.ts +++ b/src/client/puppet-service.ts @@ -1863,6 +1863,24 @@ class PuppetService extends PUPPET.Puppet { return response.getQrcode() } + override async roomParseDynamicQRCode (url: string): Promise { + log.verbose('PuppetService', 'roomParseDynamicQRCode(%s)', url) + + const request = new grpcPuppet.RoomParseDynamicQRCodeRequest() + request.setUrl(url) + + const response = await util.promisify( + this.grpcManager.client.roomParseDynamicQRCode + .bind(this.grpcManager.client), + )(request) + + return { + qrcode: response.getQrcode(), + qrcodeImgUrl: response.getQrcodeImageUrl(), + roomName: response.getRoomName(), + } + } + override async roomMemberList (roomId: string) : Promise { log.verbose('PuppetService', 'roomMemberList(%s)', roomId) @@ -1998,6 +2016,25 @@ class PuppetService extends PUPPET.Puppet { )(request) } + override async roomInvitationAcceptByQRCode ( + qrcode: string, + ): Promise { + log.verbose('PuppetService', 'roomInvitationAcceptByQRCode(%s)', qrcode) + + const request = new grpcPuppet.RoomInvitationAcceptByQRCodeRequest() + request.setQrcode(qrcode) + + const response = await util.promisify( + this.grpcManager.client.roomInvitationAcceptByQRCode + .bind(this.grpcManager.client), + )(request) + + return { + roomId: response.getRoomId(), + chatId: response.getChatId(), + } + } + override async roomInvitationRawPayload ( id: string, ): Promise { diff --git a/src/server/puppet-implementation.ts b/src/server/puppet-implementation.ts index 6f53e444..3ee6cc32 100644 --- a/src/server/puppet-implementation.ts +++ b/src/server/puppet-implementation.ts @@ -1503,6 +1503,25 @@ function puppetImplementation ( } }, + roomInvitationAcceptByQRCode: async (call, callback) => { + log.verbose('PuppetServiceImpl', 'roomInvitationAcceptByQRCode()') + + try { + const qrcode = call.request.getQrcode() + + const result = await puppet.roomInvitationAcceptByQRCode(qrcode) + + const response = new grpcPuppet.RoomInvitationAcceptByQRCodeResponse() + response.setRoomId(result.roomId) + response.setChatId(result.chatId) + + return callback(null, response) + + } catch (e) { + return grpcError('roomInvitationAccept', e, callback) + } + }, + roomInvitationPayload: async (call, callback) => { log.verbose('PuppetServiceImpl', 'roomInvitationPayload()') @@ -1681,6 +1700,26 @@ function puppetImplementation ( } }, + roomParseDynamicQRCode: async (call, callback) => { + log.verbose('PuppetServiceImpl', 'roomParseDynamicQRCode()') + + try { + const url = call.request.getUrl() + + const qrcodeInfo = await puppet.roomParseDynamicQRCode(url) + + const response = new grpcPuppet.RoomParseDynamicQRCodeResponse() + response.setQrcode(qrcodeInfo.qrcode) + response.setQrcodeImageUrl(qrcodeInfo.qrcodeImgUrl) + response.setRoomName(qrcodeInfo.roomName) + + return callback(null, response) + + } catch (e) { + return grpcError('roomParseDynamicQRCode', e, callback) + } + }, + roomQuit: async (call, callback) => { log.verbose('PuppetServiceImpl', 'roomQuit()')