wechaty/wechaty-puppet-padchat

Support ChatHistory messages

Closed this issue · 6 comments

I didn't use provided issue template since this is an enhancement request instead of an issue.

Wechaty works well for many types of messages including Text, Image, Video, etc. I'm here to ask for a new feature of supporting the reading and extracting sub-messages from a ChatHistory message forwarded from other conversations.

A ChatHistory message is generated by following steps:

  1. go to an existing conversation and hold on one of the messages
  2. tap Multiselect (It is now Select on newer versions of WeChat)
  3. pick the messages you'd like to forward
  4. tap the Forward icon on the bottom-left of the toolbar on the bottom of screen
  5. select Combine and forward and choose a contact to forward to

ChatHistory message is an efficient way for archiving information. So it'll be nice if Wechaty could provide the functionality out of box to extract this history message as some kind of structured data.

Note that, I can already get an XML payload from message.text() method (attached at the end), so it's already possible to analyze forwarded text messages on top of current APIs. But there are two major problems:

  1. I CAN NOT extract multi-media messages, since their content are not provided inline and are encrypted and need to be downloaded in separated invocations which can not be performed based on current provided APIs
  2. Extracting these messages manually could be costly for developers and it's not easy to keep up-to-date supporting as many message types as you do along with new releases of puppets

So here I'm providing two possible implementation paths:

  1. Provide some APIs to help download encrypted content of multi-media sub-messages in ChatHistory messages so that people like me can build their own support
  2. Provide an out-of-box support for the ChatHistory message type

Here is an example of a ChatHistory message:

<?xml version="1.0" encoding="UTF-8"?>
<recordinfo>
   <fromscene>3</fromscene>
   <favusername>chan</favusername>
   <title>Group Chat History</title>
   <desc>屿松: [Video]
林森: [File] XPLANE_VT101_SketchBook.pdf</desc>
   <info>屿松: [Video]
林森: [File] XPLANE_VT101_SketchBook.pdf</info>
   <datalist count="3">
      <dataitem datatype="4" subtype="0" dataid="0" htmlid="0">
         <datafmt>mp4</datafmt>
         <sourcename>屿松</sourcename>
         <sourcetime>2018-12-21 22:42</sourcetime>
         <thumbsourcepath>/var/mobile/Containers/Data/Application/182D457C4EA8-3EAA-4433-A143-B6B33D8F/Documents/53f13aef56722cdb6de4634d5087f474/Video/fae600e744c7bc69ba65f1993a23045d/3877.video_thum</thumbsourcepath>
         <thumbsize>3978</thumbsize>
         <datasourcepath>/var/mobile/Containers/Data/Application/182D457C4EA8-3EAA-4433-A143-B6B33D8F/Documents/aef56722cdd500e744c7bc69087f53f13b6de4634474/Video/fae65f1996ba3a23045d/3877.mp4</datasourcepath>
         <cdndataurl>3054020100044d304b020100020487b93d3802032f4f5602040f7ac2dc02045c21c24a0426777875706c6f61645f6368616e6578743537385f313534353731363239365f305f6e6f4165730204010400040201000400</cdndataurl>
         <cdndatakey>8af3a52db7543318b720dc48ff45dacd</cdndatakey>
         <cdnthumburl>3054020100044d304b020100020487b93d3802032f4f5602040f7ac2dc02045c21c2480426777875706c6f61645f6368616e6578743537385f313534353731363239365f305f7468756d620204010400010201000400</cdnthumburl>
         <cdnthumbkey>bce2f1f6b8a7e20bd6f76bfc694ca1ec</cdnthumbkey>
         <fullmd5>5095f0fd32bfb44bca18e52ffc3a6a51</fullmd5>
         <thumbfullmd5>6846e1284d0d7c9870fd547cde357905</thumbfullmd5>
         <datasize>1586921</datasize>
         <cdnencryver>1</cdnencryver>
         <duration>10</duration>
         <srcChatname>1203541653@chatroom</srcChatname>
         <srcMsgLocalid>3877</srcMsgLocalid>
         <srcMsgCreateTime>1545403335</srcMsgCreateTime>
         <dataitemsource>
            <realchatname>heart_nd</realchatname>
         </dataitemsource>
         <streamvideo>
            <streamvideourl />
            <streamvideototaltime>0</streamvideototaltime>
            <streamvideotitle />
            <streamvideowording />
            <streamvideoweburl />
            <streamvideothumburl />
            <streamvideopublishid />
            <streamvideoaduxinfo />
         </streamvideo>
         <illegalType>1</illegalType>
      </dataitem>
      <dataitem datatype="8" subtype="0" dataid="1" htmlid="1">
         <datafmt>pdf</datafmt>
         <sourcename>林森</sourcename>
         <sourcetime>2018-12-24 23:53</sourcetime>
         <datatitle>XPLANE_VT101_SketchBook.pdf</datatitle>
         <datasourcepath>/var/mobile/Containers/Data/Application/3D8FB6B3-4433-3EAA-A143-2D457C418EA8/Documents/aef5087f53f13b6de46356722cdd4474/OpenData/fa230199600e744c7ae65f69ba3bc45d/4052.pdf</datasourcepath>
         <cdndataurl>304c24d0420777875706c6f61645f6368616e6578743537385f313534353731363239365f310204010400050273045020100020487b93d3802032f4f560100e02010004402040f7ac2dc02045c210400</cdndataurl>
         <cdndatakey>fc5baeaeafdb2559d31700be06c235ea</cdndatakey>
         <fullmd5>1c3da50949018f12afbeb1e7b81eddea</fullmd5>
         <datasize>2442269</datasize>
         <cdnencryver>1</cdnencryver>
         <srcChatname>1203541653@chatroom</srcChatname>
         <srcMsgLocalid>4052</srcMsgLocalid>
         <srcMsgCreateTime>1545666826</srcMsgCreateTime>
         <dataitemsource>
            <realchatname>wxid_a011ldx307rq5u</realchatname>
         </dataitemsource>
      </dataitem>
      <dataitem datatype="1" subtype="0" dataid="1" htmlid="1">
         <sourcename>Nick</sourcename>
         <sourcetime>2018-12-24 23:53</sourcetime>
         <datadesc>我不知道啊,谁说的?</datadesc>
         <cdnencryver>1</cdnencryver>
         <srcChatname>1203541653@chatroom</srcChatname>
         <srcMsgLocalid>21163</srcMsgLocalid>
         <srcMsgCreateTime>1545666826</srcMsgCreateTime>
         <dataitemsource>
            <realchatname>loopigloo</realchatname>
         </dataitemsource>
      </dataitem>
   </datalist>
</recordinfo>

Hope it helps and look forward to your response.

Thanks for the issue, we haven't supported this yet, but PR is welcome, you can contact @windmemory for more detail.

Well, I'm already working on some projects extracting ChatHistory messages.
But, as stated in the initial post, there is one blocking problem makes me not possible to support multi-media messages as Wechaty and underlying puppets DO NOT provide any standalone APIs for downloading multi-media content based on cdndataurl and cdndatakey things.

Only this is solved could my solution move on. If so, I'll be horned to file a PR.

It seems a new class CdnManager was added recently, let me try if it is good for use.
https://github.com/botorange/wechaty-puppet-padpro/blob/master/src/manager/cdn-manager.ts

It's now confirmed that this CdnManager could be used to download attachment files, but not images.

@jijiechen Could you move this issue to https://github.com/chatie/wechaty/issues Since wechaty don't support this API yet. We can discuss there.