Skip to content

Commit

Permalink
Merge pull request #71 from juzibot/ref/rich-text-payload
Browse files Browse the repository at this point in the history
Ref/rich text payload
  • Loading branch information
hcfw007 authored Jan 18, 2024
2 parents 8226442 + fd0387a commit 538bb6f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
12 changes: 6 additions & 6 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.89",
"version": "1.0.90",
"description": "Puppet Service for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -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.79",
"@juzi/wechaty-puppet": "^1.0.81",
"@juzi/wechaty-puppet-mock": "^1.0.1",
"@swc/core": "1.3.39",
"@types/google-protobuf": "^3.15.5",
Expand All @@ -63,17 +63,17 @@
"esquery": "1.4.0",
"get-port": "^6.1.2",
"temp": "^0.9.4",
"ts-node": "10.9.1",
"typed-emitter": "^1.5.0-from-event",
"typescript": "4.7.4",
"utility-types": "^3.10.0",
"why-is-node-running": "^2.2.1",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"why-is-node-running": "^2.2.1"
},
"peerDependencies": {
"@juzi/wechaty-puppet": "^1.0.72"
},
"dependencies": {
"@juzi/wechaty-grpc": "^1.0.75",
"@juzi/wechaty-grpc": "^1.0.76",
"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 @@ -1307,6 +1307,31 @@ class PuppetService extends PUPPET.Puppet {
type : response.getType() as number,
quoteId : response.getQuoteId(),
additionalInfo: response.getAdditionalInfo(),
textContent : [],
}

const textContentListPb = response.getTextContentsList()
for (const textContentPb of textContentListPb) {
const type = textContentPb.getType()
const contentData = {
type,
text: textContentPb.getText(),
} as PUPPET.types.TextContent
switch (contentData.type) {
case PUPPET.types.TextContentType.Regular:
break
case PUPPET.types.TextContentType.At: {
const data = textContentPb.getData()
const contactId = data?.getContactId()
contentData.data = {
contactId: contactId || '',
}
break
}
default:
log.warn('PuppetService', `unknown text content type ${type}`)
}
payload.textContent?.push(contentData)
}

// log.silly('PuppetService', 'messageRawPayload(%s) cache SET', id)
Expand Down
25 changes: 25 additions & 0 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { log } from '../config.js'
import { grpcError } from './grpc-error.js'
import { EventStreamManager } from './event-stream-manager.js'
import { OptionalBooleanUnwrapper, OptionalBooleanWrapper, callRecordPayloadToPb, channelPayloadToPb, chatHistoryPayloadToPb, postPbToPayload, urlLinkPayloadToPb } from '../utils/pb-payload-helper.js'
import { TextContentType } from '@juzi/wechaty-puppet/types'

function puppetImplementation (
puppet : PUPPET.impls.PuppetInterface,
Expand Down Expand Up @@ -935,6 +936,30 @@ function puppetImplementation (
response.setQuoteId(payload.quoteId || '')
response.setAdditionalInfo(payload.additionalInfo || '')

const textContents = payload.textContent
const textContentPbs = []
for (const textContent of (textContents || [])) {
const textContentPb = new grpcPuppet.TextContent()
const type = textContent.type
textContentPb.setText(textContent.text)
textContentPb.setType(type)
switch (type) {
case TextContentType.Regular:
break
case TextContentType.At: {
const data = new grpcPuppet.TextContentData()
data.setContactId(textContent.data.contactId)
textContentPb.setData(data)
break
}
default:
log.warn('PuppetServiceImpl', `unknown text content type ${type}`)
break
}
textContentPbs.push(textContentPb)
}
response.setTextContentsList(textContentPbs)

return callback(null, response)

} catch (e) {
Expand Down

0 comments on commit 538bb6f

Please sign in to comment.