Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add send post message #76

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,31 @@ class PuppetService extends PUPPET.Puppet {
}
}

override async messageSendPost (
conversationId: string,
postPayload: PUPPET.payloads.PostClient,
): Promise<void | string> {
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<PUPPET.payloads.UrlLink> {
log.verbose('PuppetService', 'messageUrl(%s)', messageId)

Expand Down
34 changes: 34 additions & 0 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()')

Expand Down
Loading