Skip to main content

Polyglot: DIY

DIY Wechaty

note

Create your own Wechaty Puppet Provider

We built Wechaty in TypeScript in the early days, it is not hard to translate the TypeScript(TS) to Python, Go, and Java languages because wechaty has only 3,000 lines of the TS code, they are well designed and de-coupled by the wechaty-puppet abstraction. So after we have translated those 3,000 lines of TypeScript code, we will almost be done.

As we have already an ecosystem of Wechaty in TypeScript, so we will not have to implement everything in other languages, especially, in Feb 2020, we have finished the wechaty_grpc service abstracting module with the wechaty-puppet-service implementation.

Architecture#

The following diagram shows out that we can reuse almost everything in TypeScript, and what we need to do is only the block located at the top right of the diagram: Wechaty (Polyglot).

+--------------------------+ +--------------------------+
| | | |
| Wechaty (TypeScript) | | Wechaty(Polyglot) |
| | | Python, Go, Java, etc. |
+--------------------------+ +--------------------------+
+-------------------------------------------------------+
| Wechaty Puppet Servuce |
| |
| (wechaty-puppet-service) |
+-------------------------------------------------------+
+--------------------- wechaty_grpc ----------------------+
+-------------------------------------------------------+
| Wechaty Puppet Abstract |
| |
| (wechaty-puppet) |
+-------------------------------------------------------+
+--------------------------+ +--------------------------+
| Pad Protocol | | Web Protocol |
| | | |
| wechaty-puppet-padlocal | | (wechaty-puppet-wechat) |
+--------------------------+ +--------------------------+
+--------------------------+ +--------------------------+
| Friday Protocol | | Mac Protocol |
| | | |
| (wechaty-puppet-frida) | | (wechaty-puppet-mac) |
+--------------------------+ +--------------------------+

Chart made by AsciiFlow

Check-list#

  • TS: TypeScript
  • SLOC: Source Lines Of Code

Wechaty Internal Modules#

  1. Class Wechaty @wj-mCat
  2. Class Contact
  3. Class ContactSelf
  4. Class Message
  5. Class Room
  6. Class Image @wj-mCat
  7. Class Accessory @huan
  8. Class Config @wj-mCat
  9. Class Favorite
  10. Class Friendship
  11. Class MiniProgram
  12. Class RoomInvitation
  13. Class Tag
  14. Class UrlLink

Wechaty External Modules#

  1. Class FileBox
  2. Class MemoryCard
  3. Class WechatyPuppet
  4. Class WechatyPuppetHostie

Example: How to Translate TypeScript to Python#

There's a 100 lines class named Image in charge of downloading the WeChat image to different sizes.

It is a great example for demonstrating how do we translate the TypeScript to Python in Wechaty Way:

Image Class Source Code#

If you are interested in the translation and want to look at how it works, it will be a good start from reading and comparing those two Image class files in TypeScript and Python at the same time.

History#

Last updated on by Souvik Biswas