Skip to content

Commit

Permalink
Merge pull request #1283 from wechaty/shraddhavp-patch-5
Browse files Browse the repository at this point in the history
Updated the Polyglot Do it yourself section
  • Loading branch information
shraddhavp authored Sep 18, 2021
2 parents 315a4f7 + 0ecb8d0 commit 8dc59f3
Showing 1 changed file with 23 additions and 113 deletions.
136 changes: 23 additions & 113 deletions docusaurus/docs/polyglot/diy/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ title: 'Polyglot: DIY'

[![DIY Wechaty](https://img.shields.io/badge/Wechaty-DIY-brightgreen)](overview.md)

:::note
Wechaty is mainly built on TypeScript, it is not very hard to translate the TypeScript(TS) to other programming languages [wechaty](https://github.com/wechaty/wechaty) has only 3,000 lines of the TS code, that are well designed and de-coupled by the [wechaty-puppet](https://github.com/wechaty/wechaty-puppet/) abstraction. So after translation of those 3,000 lines of TypeScript code, Wechaty can be used in any programming language.

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](https://github.com/wechaty/wechaty) has only 3,000 lines of the TS code, they are well designed and de-coupled by the [wechaty-puppet](https://github.com/wechaty/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](https://github.com/wechaty/grpc) service abstracting module with the [wechaty-puppet-service](https://github.com/wechaty/wechaty-puppet-service) implementation.
Wechaty already has an ecosystem in TypeScript, so you will not have to implement everything in other languages, especially since, in Feb 2020, Wechaty finished the [wechaty-grpc](https://github.com/wechaty/grpc) service abstracting module with the [wechaty-puppet-service](https://github.com/wechaty/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)`.
![Polyglot Architecture](/img/polyglot-architecure.webp)

```ascii
+--------------------------+ +--------------------------+
Expand Down Expand Up @@ -46,9 +41,9 @@ The following diagram shows out that we can reuse almost everything in TypeScrip
| wechaty-puppet-padlocal | | (wechaty-puppet-wechat) |
+--------------------------+ +--------------------------+
+--------------------------+ +--------------------------+
| Friday Protocol | | Mac Protocol |
| Windows Protocol | | WhatsApp Protocol |
| | | |
| (wechaty-puppet-frida) | | (wechaty-puppet-mac) |
| (wechaty-puppet-xp) | | (wechaty-puppet-whatsapp)|
+--------------------------+ +--------------------------+
```

Expand All @@ -61,112 +56,27 @@ The following diagram shows out that we can reuse almost everything in TypeScrip

### Wechaty Internal Modules

1. [ ] Class Wechaty @wj-mCat
- TS SLOC(1160): <https://github.com/wechaty/wechaty/blob/main/src/wechaty.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Contact
- TS SLOC(804): <https://github.com/wechaty/wechaty/blob/main/src/user/contact.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class ContactSelf
- TS SLOC(199): <https://github.com/wechaty/wechaty/blob/main/src/user/contact-self.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Message
- TS SLOC(1054): <https://github.com/wechaty/wechaty/blob/main/src/user/message.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Room
- TS SLOC(1194): <https://github.com/wechaty/wechaty/blob/main/src/user/room.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Image @wj-mCat
- TS SLOC(60): <https://github.com/wechaty/wechaty/blob/main/src/user/image.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Accessory @huan
- TS SLOC(179): <https://github.com/wechaty/wechaty/blob/main/src/accessory.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Config @wj-mCat
- TS SLOC(187): <https://github.com/wechaty/wechaty/blob/main/src/config.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Favorite
- TS SLOC(52): <https://github.com/wechaty/wechaty/blob/main/src/user/favorite.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Friendship
- TS SLOC(417): <https://github.com/wechaty/wechaty/blob/main/src/user/friendship.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class MiniProgram
- TS SLOC(70): <https://github.com/wechaty/wechaty/blob/main/src/user/mini-program.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class RoomInvitation
- TS SLOC(317): <https://github.com/wechaty/wechaty/blob/main/src/user/room-invitation.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class Tag
- TS SLOC(190): <https://github.com/wechaty/wechaty/blob/main/src/user/tag.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class UrlLink
- TS SLOC(107): <https://github.com/wechaty/wechaty/blob/main/src/user/url-link.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. **Class Wechaty @wj-mCat** TS SLOC(1160): <https://github.com/wechaty/wechaty/blob/master/src/wechaty.ts>
1. **Class Contact** TS SLOC(804): <https://github.com/wechaty/wechaty/blob/master/src/user/contact.ts>
1. **Class ContactSelf** TS SLOC(199): <https://github.com/wechaty/wechaty/blob/master/src/user/contact-self.ts>
1. **Class Message** TS SLOC(1054): <https://github.com/wechaty/wechaty/blob/master/src/user/message.ts>
1. **Class Room** TS SLOC(1194): <https://github.com/wechaty/wechaty/blob/master/src/user/room.ts>
1. **Class Image @wj-mCat** TS SLOC(60): <https://github.com/wechaty/wechaty/blob/master/src/user/image.ts>
1. **Class Accessory @huan** TS SLOC(179): <https://github.com/wechaty/wechaty/blob/master/src/accessory.ts>
1. **Class Config @wj-mCat** TS SLOC(187): <https://github.com/wechaty/wechaty/blob/master/src/config.ts>
1. **Class Favorite** TS SLOC(52): <https://github.com/wechaty/wechaty/blob/master/src/user/favorite.ts>
1. **Class Friendship** TS SLOC(417): <https://github.com/wechaty/wechaty/blob/master/src/user/friendship.ts>
1. **Class MiniProgram** TS SLOC(70): <https://github.com/wechaty/wechaty/blob/master/src/user/mini-program.ts>
1. **Class RoomInvitation** TS SLOC(317): <https://github.com/wechaty/wechaty/blob/master/src/user/room-invitation.ts>
1. **Class Tag** TS SLOC(190): <https://github.com/wechaty/wechaty/blob/master/src/user/tag.ts>
1. **Class UrlLink** TS SLOC(107): <https://github.com/wechaty/wechaty/blob/master/src/user/url-link.ts>

### Wechaty External Modules

1. [ ] Class FileBox
- TS SLOC(638): <https://github.com/huan/file-box/blob/master/src/file-box.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class MemoryCard
- TS SLOC(376): <https://github.com/huan/memory-card/blob/master/src/memory-card.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class WechatyPuppet
- TS SLOC(1115): <https://github.com/wechaty/wechaty-puppet/blob/main/src/puppet.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation
1. [ ] Class WechatyPuppetHostie
- TS SLOC(909): <https://github.com/wechaty/wechaty-puppet-hostie/blob/master/src/grpc/puppet-client.ts>
- [ ] Code
- [ ] Unit Tests
- [ ] Documentation

## 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

- TypeScript: <https://github.com/wechaty/wechaty/blob/main/src/user/image.ts>
- Python: <https://github.com/wechaty/python-wechaty/blob/master/src/wechaty/user/image.py>

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.
1. **Class FileBox** TS SLOC(638): <https://github.com/huan/file-box/blob/master/src/file-box.ts>
1. **Class MemoryCard** TS SLOC(376): <https://github.com/huan/memory-card/blob/master/src/memory-card.ts>
1. **Class WechatyPuppet** TS SLOC(1115): <https://github.com/wechaty/wechaty-puppet/blob/master/src/puppet.ts>
1. **Class WechatyPuppetHostie** TS SLOC(909): <https://github.com/wechaty/wechaty-puppet-hostie/blob/master/src/grpc/puppet-client.ts>

## History

Expand Down

0 comments on commit 8dc59f3

Please sign in to comment.