diff --git a/src/client/puppet-service.ts b/src/client/puppet-service.ts index 8d2bcce9..01499304 100644 --- a/src/client/puppet-service.ts +++ b/src/client/puppet-service.ts @@ -873,6 +873,28 @@ class PuppetService extends PUPPET.Puppet { return contactId } + override async messageChannel ( + messageId: string, + ): Promise { + log.verbose('PuppetService', 'messageChannel(%s)', messageId) + + const request = new grpcPuppet.MessageChannelRequest() + request.setId(messageId) + + const response = await util.promisify( + this.grpcManager.client.messageChannel + .bind(this.grpcManager.client), + )(request) + + const channelPayload = response.getChannel()!.toObject() + + const payload: PUPPET.payloads.Channel = { + ...channelPayload, + } + + return payload + } + override async messageSendMiniProgram ( conversationId : string, miniProgramPayload : PUPPET.payloads.MiniProgram, @@ -951,6 +973,38 @@ class PuppetService extends PUPPET.Puppet { } } + override async messageSendChannel ( + conversationId: string, + channelPayload: PUPPET.payloads.Channel, + ): Promise { + log.verbose('PuppetService', 'messageSendChannel(%s, "%s")', conversationId, JSON.stringify(channelPayload)) + + const request = new grpcPuppet.MessageSendChannelRequest() + request.setConversationId(conversationId) + + const pbChannelPayload = new grpcPuppet.ChannelPayload() + if (channelPayload.avatar) { pbChannelPayload.setAvatar(channelPayload.avatar) } + if (channelPayload.coverUrl) { pbChannelPayload.setCoverUrl(channelPayload.coverUrl) } + if (channelPayload.desc) { pbChannelPayload.setDesc(channelPayload.desc) } + if (channelPayload.extras) { pbChannelPayload.setExtras(channelPayload.extras) } + if (channelPayload.feedType) { pbChannelPayload.setFeedType(channelPayload.feedType) } + if (channelPayload.nickname) { pbChannelPayload.setNickname(channelPayload.nickname) } + if (channelPayload.thumbUrl) { pbChannelPayload.setThumbUrl(channelPayload.thumbUrl) } + if (channelPayload.url) { pbChannelPayload.setUrl(channelPayload.url) } + request.setChannel(pbChannelPayload) + + const response = await util.promisify( + this.grpcManager.client.messageSendChannel + .bind(this.grpcManager.client), + )(request) + + const messageId = response.getId() + + if (messageId) { + return messageId + } + } + override async messageRecall ( messageId: string, ): Promise { diff --git a/src/server/puppet-implementation.ts b/src/server/puppet-implementation.ts index 02f7312a..ceb70aad 100644 --- a/src/server/puppet-implementation.ts +++ b/src/server/puppet-implementation.ts @@ -695,6 +695,34 @@ function puppetImplementation ( } }, + messageChannel: async (call, callback) => { + log.verbose('PuppetServiceImpl', 'messageChannel()') + + try { + const id = call.request.getId() + + const payload = await puppet.messageChannel(id) + + const response = new grpcPuppet.MessageChannelResponse() + + const pbChannelPayload = new grpcPuppet.ChannelPayload() + if (payload.avatar) { pbChannelPayload.setAvatar(payload.avatar) } + if (payload.coverUrl) { pbChannelPayload.setCoverUrl(payload.coverUrl) } + if (payload.desc) { pbChannelPayload.setDesc(payload.desc) } + if (payload.extras) { pbChannelPayload.setExtras(payload.extras) } + if (payload.feedType) { pbChannelPayload.setFeedType(payload.feedType) } + if (payload.nickname) { pbChannelPayload.setNickname(payload.nickname) } + if (payload.thumbUrl) { pbChannelPayload.setThumbUrl(payload.thumbUrl) } + if (payload.url) { pbChannelPayload.setUrl(payload.url) } + response.setChannel(pbChannelPayload) + + return callback(null, response) + + } catch (e) { + return grpcError('messageMiniProgram', e, callback) + } + }, + messagePayload: async (call, callback) => { log.verbose('PuppetServiceImpl', 'messagePayload()') @@ -992,6 +1020,35 @@ function puppetImplementation ( } }, + messageSendChannel: async (call, callback) => { + log.verbose('PuppetServiceImpl', 'messageSendChannel()') + + try { + const conversationId = call.request.getConversationId() + const pbChannelPayload = call.request.getChannel()?.toObject() + + if (!pbChannelPayload) { + return grpcError('messageSendUrl', new Error().stack, callback) + } + const payload: PUPPET.payloads.Channel = { + ...pbChannelPayload, + } + + const messageId = await puppet.messageSendChannel(conversationId, payload) + + const response = new grpcPuppet.MessageSendChannelResponse() + + if (messageId) { + response.setId(messageId) + } + + return callback(null, response) + + } catch (e) { + return grpcError('messageSendChannel', e, callback) + } + }, + messageUrl: async (call, callback) => { log.verbose('PuppetServiceImpl', 'messageUrl()')