linyimin0812 / wechaty-puppet-ioscat

Puppet Ios Cat for Wechaty
https://www.npmjs.com/package/wechaty-puppet-ioscat
Apache License 2.0
37 stars 11 forks source link

Data Format Conversion #7

Open linyimin0812 opened 6 years ago

linyimin0812 commented 6 years ago

anynoe has the idea that convert the follow xml to 你邀请"b1d5811c-aebe-4505-94bf-9e9d108ea3e8、b5333b25-1976-4d0b-a627-c4eb77361e80"加入了群聊

xml infomation

<sysmsg type="sysmsgtemplate">
  <sysmsgtemplate>
    <content_template type="tmpl_type_profilewithrevoke">
      <plain><![CDATA[]]></plain>
      <template><![CDATA[你邀请"$names$"加入了群聊  $revoke$]]></template>
      <link_list>
        <link name="names" type="link_profile">
          <memberlist>
            <member>
              <username><![CDATA[wxid_6023860170912]]></username>
              <nickname><![CDATA[b1d5811c-aebe-4505-94bf-9e9d108ea3e8]]></nickname>
            </member>
            <member>
              <username><![CDATA[wxid_thr4g3jd59a021]]></username>
              <nickname><![CDATA[b5333b25-1976-4d0b-a627-c4eb77361e80]]></nickname>
            </member>
          </memberlist>
          <separator><![CDATA[、]]></separator>
        </link>
        <link name="revoke" type="link_revoke" hidden="1">
          <title><![CDATA[撤销]]></title>
          <usernamelist>
            <username><![CDATA[wxid_6023860170912]]></username>
            <username><![CDATA[wxid_thr4g3jd59a021]]></username>
          </usernamelist>
        </link>
      </link_list>
    </content_template>
  </sysmsgtemplate>
</sysmsg>
huan commented 6 years ago

Please have a look at https://github.com/lijiarui/wechaty-puppet-padchat/blob/7c4353225aa5a166c43c3a19264b83fa42718eb7/src/pure-function-helpers/xml2json.ts

I believe this utility function can help you turn XML into json format, then you can deal with the data easily.

linyimin0812 commented 6 years ago

ok,I will have a try.Thanks very much

huan commented 6 years ago

Please have a look at https://github.com/lijiarui/wechaty-puppet-padchat/pull/143, it's all about XML to JSON.

linyimin0812 commented 6 years ago

OK, I will have a try, thanks very much.

linyimin0812 commented 6 years ago

https://github.com/linyimin-bupt/wechaty-puppet-ioscat/blob/master/src/pure-function-helper/room-event-xml-message-parser.ts

huan commented 6 years ago
  1. To reference the issue number in the commit message is a good practice than post the source code code to issue comment.
  2. We need unit test (at least a very basic one) for the code.