From c953e6b719e87d055b646e36af4cac4df0cceddd Mon Sep 17 00:00:00 2001 From: suchang Date: Wed, 15 May 2024 11:54:20 +0800 Subject: [PATCH 1/2] feat: :sparkles: add send post message --- package.json | 2 +- src/client/puppet-service.ts | 25 +++++++++++++++++++++ src/server/puppet-implementation.ts | 34 +++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d665ad54..4b615a83 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@juzi/wechaty-puppet": "^1.0.84" }, "dependencies": { - "@juzi/wechaty-grpc": "^1.0.84", + "@juzi/wechaty-grpc": "^1.0.86", "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 169f7a13..95f4a38d 100644 --- a/src/client/puppet-service.ts +++ b/src/client/puppet-service.ts @@ -1509,6 +1509,31 @@ class PuppetService extends PUPPET.Puppet { } } + override async messageSendPost ( + conversationId: string, + postPayload: PUPPET.payloads.PostClient, + ): Promise { + log.verbose('PuppetService', 'messageSendPost("%s", %s)', conversationId, JSON.stringify(postPayload)) + + const request = new grpcPuppet.MessageSendPostRequest() + const post = await postPayloadToPb(grpcPuppet, postPayload, this.serializeFileBox.bind(this)) + request.setContent(post) + request.setConversationId(conversationId) + + log.info('PuppetService', `messageSendPost(${conversationId}, ${postPayload}) about to call grpc`) + const response = await util.promisify( + this.grpcManager.client.messageSendPost + .bind(this.grpcManager.client), + )(request) + + const messageId = response.getId() + log.info('PuppetService', `messageSendPost(${conversationId}, ${postPayload}) grpc called, messageId: ${messageId}`) + + if (messageId) { + return messageId + } + } + override async messageUrl (messageId: string): Promise { log.verbose('PuppetService', 'messageUrl(%s)', messageId) diff --git a/src/server/puppet-implementation.ts b/src/server/puppet-implementation.ts index 1029ca07..33b5e69e 100644 --- a/src/server/puppet-implementation.ts +++ b/src/server/puppet-implementation.ts @@ -1250,6 +1250,40 @@ function puppetImplementation ( } }, + messageSendPost: async (call, callback) => { + log.verbose('PuppetServiceImpl', 'messageSendPost()') + + try { + const conversationId = call.request.getConversationId() + const post = call.request.getContent() + + if (!post) { + throw new Error('no post found') + } + if ( + post.getType() === grpcPuppet.PostType.POST_TYPE_CHANNEL + || post.getType() === grpcPuppet.PostType.POST_TYPE_BROADCAST + || post.getType() === grpcPuppet.PostType.POST_TYPE_UNSPECIFIED + ) { + throw new Error('cannot send post with non-message post type') + } + + const payload = postPbToPayload(post, FileBoxUuid) + + const id = await puppet.messageSendPost(conversationId, payload) + + const response = new grpcPuppet.MessageSendPostResponse() + if (id) { + response.setId(id) + } + + return callback(null, response) + + } catch (e) { + return grpcError('messageSendPost', e, callback) + } + }, + messageUrl: async (call, callback) => { log.verbose('PuppetServiceImpl', 'messageUrl()') From 421785c83450ebb985a8cf74e79c496ae0efe279 Mon Sep 17 00:00:00 2001 From: suchang Date: Wed, 15 May 2024 11:54:25 +0800 Subject: [PATCH 2/2] 1.0.97 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b615a83..af917b8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@juzi/wechaty-puppet-service", - "version": "1.0.96", + "version": "1.0.97", "description": "Puppet Service for Wechaty", "type": "module", "exports": {