Skip to content

Commit

Permalink
Merge pull request #26 from fabian4/fix_talkerId_and_listenerId
Browse files Browse the repository at this point in the history
replace fromId by talkerId, toId by listenerId
  • Loading branch information
fabian4 authored Apr 8, 2022
2 parents 1dbc10f + c38205c commit 210d871
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-walnut",
"version": "1.11.8",
"version": "1.18.1",
"description": "Puppet Walnut for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -59,7 +59,7 @@
"@types/uuid": "^8.3.3"
},
"peerDependencies": {
"wechaty-puppet": "^1.11.12"
"wechaty-puppet": "^1.18.3"
},
"dependencies": {
"axios": "^0.24.0",
Expand Down
12 changes: 6 additions & 6 deletions src/puppet-walnut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ test('message parser for text message', async t => {
}
const messagePayload = await puppet.messageRawPayloadParser(walnutMessagePayload as WalnutMessagePayload)
t.ok(
messagePayload.toId === 'sip:[email protected]'
messagePayload.listenerId === 'sip:[email protected]'
&& messagePayload.roomId === undefined
&& messagePayload.fromId === '17928222350'
&& messagePayload.talkerId === '17928222350'
&& messagePayload.text === 'hello world'
&& messagePayload.type === PUPPET.types.Message.Text,
)
Expand Down Expand Up @@ -95,9 +95,9 @@ test('message parser for image message', async t => {
}
const messagePayload = await puppet.messageRawPayloadParser(walnutMessagePayload as WalnutMessagePayload)
t.ok(
messagePayload.toId === 'sip:[email protected]'
messagePayload.listenerId === 'sip:[email protected]'
&& messagePayload.roomId === undefined
&& messagePayload.fromId === '17928222350'
&& messagePayload.talkerId === '17928222350'
&& messagePayload.text === 'image'
&& messagePayload.type === PUPPET.types.Message.Image,
)
Expand Down Expand Up @@ -137,9 +137,9 @@ test('message parser for file message', async t => {
}
const messagePayload = await puppet.messageRawPayloadParser(walnutMessagePayload as WalnutMessagePayload)
t.ok(
messagePayload.toId === 'sip:[email protected]'
messagePayload.listenerId === 'sip:[email protected]'
&& messagePayload.roomId === undefined
&& messagePayload.fromId === '17928222350'
&& messagePayload.talkerId === '17928222350'
&& messagePayload.text === 'file'
&& messagePayload.type === PUPPET.types.Message.Attachment,
)
Expand Down
41 changes: 39 additions & 2 deletions src/puppet-walnut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ class PuppetWalnut extends PUPPET.Puppet {
*/
override async messageRawPayloadParser (rawPayload: WalnutMessagePayload): Promise<PUPPET.payloads.Message> {
const res = {
fromId: rawPayload.senderAddress.replace('tel:+86', ''),
id: rawPayload.messageId,
listenerId: rawPayload.destinationAddress,
talkerId: rawPayload.senderAddress.replace('tel:+86', ''),
text: rawPayload.messageList[0]!.contentText.toString(),
timestamp: Date.parse(rawPayload.dateTime),
toId: rawPayload.destinationAddress,
type: PUPPET.types.Message.Text,
}
const file = rawPayload.messageList[0]?.contentText[0] as FileItem
Expand Down Expand Up @@ -280,6 +280,43 @@ class PuppetWalnut extends PUPPET.Puppet {
}
}

/**
*
* Post
*
*/
override async postRawPayload (postId: string): Promise<any> {
log.verbose('PuppetWalnut', 'postRawPayload(%s)', postId)
return { postId } as any
}

override async postRawPayloadParser (rawPayload: any): Promise<PUPPET.payloads.Post> {
log.verbose('PuppetWalnut', 'postRawPayloadParser(%s)', rawPayload.id)
return rawPayload
}

override async postPublish (payload: PUPPET.payloads.Post): Promise<void | string> {
log.verbose('PuppetWalnut', 'postPublish({type: %s})',
PUPPET.types.Post[
payload.type || PUPPET.types.Post.Unspecified
],
)
}

override async postSearch (
filter : PUPPET.filters.Post,
pagination? : PUPPET.filters.PaginationRequest,
): Promise<PUPPET.filters.PaginationResponse<string[]>> {
log.verbose('PuppetWalnut', 'postSearch(%s, %s)',
JSON.stringify(filter),
JSON.stringify(pagination),
)
return {
nextPageToken: undefined,
response: [],
}
}

}

export default PuppetWalnut

0 comments on commit 210d871

Please sign in to comment.