Skip to content
Merged
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
19 changes: 14 additions & 5 deletions src/padlocal/message-parser/message-parser-friendship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from "padlocal-client-ts/dist/proto/padlocal_pb";
import { Puppet, FriendshipPayloadConfirm, FriendshipPayloadVerify, FriendshipType } from "wechaty-puppet";
import { FriendshipPayloadReceive } from "wechaty-puppet/src/schemas/friendship";
import { FriendshipPayloadReceive, FriendshipSource } from "wechaty-puppet/src/schemas/friendship";
import { isContactId, isIMContactId } from "../utils/is-type";
import { xmlToJson } from "../utils/xml-to-json";
import { MessageParserRetType } from "./message-parser";
Expand Down Expand Up @@ -28,8 +28,10 @@ interface ReceiveXmlSchema {
content: string;
scene: string;
ticket: string;
sourcenickname?: string;
sourceusername?: string;
sourcenickname?: string;
sharecardusername?: string;
sharecardnickname?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it seems the sourceXXX and shareXXX name conversion is coming from the WeChat server data payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

};
};
}
Expand Down Expand Up @@ -84,7 +86,7 @@ export default async (_puppet: Puppet, message: Message.AsObject): Promise<Messa
} else {
const verifyXml = await isReceive(message);
if (verifyXml) {
return {
const friendshipPayload = {
contactId: verifyXml.msg.$.fromusername,
hello: verifyXml.msg.$.content,
id: message.id,
Expand All @@ -93,9 +95,16 @@ export default async (_puppet: Puppet, message: Message.AsObject): Promise<Messa
ticket: verifyXml.msg.$.ticket,
timestamp: message.createtime,
type: FriendshipType.Receive,
sourceNickName: verifyXml.msg.$.sourcenickname,
sourceUserName: verifyXml.msg.$.sourceusername,
} as FriendshipPayloadReceive;
if(verifyXml.msg.$.sourceusername || verifyXml.msg.$.sharecardnickname){
friendshipPayload.source = {
sourceContactId:verifyXml.msg.$.sourceusername,
sourceName:verifyXml.msg.$.sourcenickname,
shareCardContactId:verifyXml.msg.$.sharecardusername,
shareCardName: verifyXml.msg.$.sharecardnickname
} as FriendshipSource;
}
return friendshipPayload;
}

return null;
Expand Down