This repository has been archived by the owner on Jun 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d5381d
commit a2cc86f
Showing
8 changed files
with
436 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AppPayload } from "wechaty-puppet"; | ||
|
||
export const generateAppXMLMessage = ({ title, des, url, thumburl, appType }: AppPayload): string => { | ||
return ` | ||
<appmsg appid="" sdkver="0"> | ||
<title>${title}</title> | ||
<des>${des}</des> | ||
<username></username> | ||
<action>view</action> | ||
<type>${appType}</type> | ||
<showtype>0</showtype> | ||
<url>${url}</url> | ||
<contentattr>0</contentattr> | ||
${thumburl ? '<thumburl>' + thumburl + '</thumburl>' : ''} | ||
</appmsg> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
319 changes: 319 additions & 0 deletions
319
src/pure-function-helpers/message-app-payload-parser.spec.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { toJson } from 'xml2json' | ||
|
||
import { | ||
PadchatMessagePayload, PadchatAppMessagePayload | ||
} from '../padchat-schemas' | ||
|
||
import { isPayload } from './is-type' | ||
import { AppType } from 'wechaty-puppet' | ||
|
||
export function appMessageParser(rawPayload: PadchatMessagePayload): PadchatAppMessagePayload | null { | ||
if (!isPayload(rawPayload)) { | ||
return null | ||
} | ||
|
||
const { content, msg_id, timestamp, from_user } = rawPayload | ||
|
||
interface XmlSchema { | ||
msg: { | ||
appmsg: { | ||
title: string, | ||
des: string, | ||
type: number, | ||
url: string, | ||
appattach: { | ||
totallen: string, | ||
attachid: any, | ||
emoticonmd5: any, | ||
fileext: any, | ||
cdnthumbaeskey: any, | ||
aeskey: any | ||
}, | ||
thumburl: string, | ||
md5: any, | ||
recorditem?: string | ||
}, | ||
fromusername: string, | ||
appinfo: { | ||
appname: any | ||
} | ||
} | ||
} | ||
|
||
const tryXmlText = content.replace(/^[^\n]+\n/, '') | ||
|
||
try { | ||
const jsonPayload = toJson(tryXmlText, { object: true }) as XmlSchema | ||
|
||
console.log(jsonPayload.msg.appmsg.type === AppType.Link) | ||
return { | ||
title: jsonPayload.msg.appmsg.title, | ||
des: jsonPayload.msg.appmsg.des, | ||
url: jsonPayload.msg.appmsg.url, | ||
thumburl: jsonPayload.msg.appmsg.thumburl, | ||
type: jsonPayload.msg.appmsg.type | ||
} | ||
} catch (e) { | ||
console.error(e) | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters