generated from wechaty/puppet-mock
-
Notifications
You must be signed in to change notification settings - Fork 89
Message payload parsers list
padlocal edited this page Jun 9, 2022
·
2 revisions
- Test the message content with
<type>24</type>
- If match, call the following function, to get plain text from 笔记:
function WxNoteMsgFilter(content) {
return '[笔记]\n'+ he.decode(he.decode(content.replace(/.*?<type>24<\/type>.*?<recorditem>(?:<recordinfo>|<!\[CDATA\[<recordinfo>).*?(?:><datadesc>|<datadesc>)(.*?)(<|<)\/datadesc(>|>).*?<\/recorditem>.*/s,'$1')))
}
Thanks @suntong
- Test the message content with
<type>19</type>
- If match, call the following function, to get plain text from 合并转发 messages:
async function ChatHistoryMsgFilter(content) {
if (!/<appmsg .*<type>19<\/type>/si.test(content))
return content
const summary = he.decode(content)
.replace(/.*?<msg>.*?<title>(.*?)<\/title>.*?<des>(.*?)<\/des>.*/s,'\n= 合并转发$1 =\n\n== 简介 ==\n$2\n\n== 详细 ==\n\n')
.replace(/^(.{1,30}?):/gm,'\n[$1]: ')
let details
const details0 = he.decode(content)
try {
const details1 = await xmlToJson(details0.replace(/.*?<msg>.*?<recorditem>(.*?)<\/recorditem>.*/s,'$1'))
if (/<recorditem><recordinfo>.*<datalist .*<datadesc>/si.test(details0)) {
details = details1.recordinfo.datalist.dataitem.map(
(d) => {
if (d.ATTR.datatype == '1')
return `[${d.sourcename}] @${d.sourcetime}\n${d.datadesc}\n\n`
else return `[${d.sourcename}] @${d.sourcetime}\n${d.datafmt}\n\n`
}).reduce(
(acc, n) => {
return acc + n;
},
'' // accumulator variable value at first iteration step
)
}
} catch (e) {
console.error( "ChatHistoryMsgFilter", e )
}
return summary + details
}
Don't be evil
GETTING STARTED
- How to Apply Token
- Getting Started with TypeScript/JavaScript(RECOMMENDED)
- Getting Started with Python/Java/Go
REFERENCE
ADVANCED GUIDES