go-wechaty
Connecting Chatbots
Wechaty is a RPA SDK for Wechat Individual Account that can help you create a chatbot in 6 lines of Go.
Voice of the Developers
"Wechaty is a great solution, I believe there would be much more users recognize it." link
— @Gcaufy, Tencent Engineer, Author of WePY"太好用,好用的想哭"
— @xinbenlv, Google Engineer, Founder of HaoShiYou.org"最好的微信开发库" link
— @Jarvis, Baidu Engineer"Wechaty让运营人员更多的时间思考如何进行活动策划、留存用户,商业变现" link
— @lijiarui, Founder & CEO of Juzi.BOT."If you know js ... try Wechaty, it's easy to use."
— @Urinx Uri Lee, Author of WeixinBot(Python)
See more at Wiki:Voice Of Developer
Join Us
Wechaty is used in many ChatBot projects by thousands of developers. If you want to talk with other developers, just scan the following QR Code in WeChat with secret code go wechaty, join our Wechaty Go Developers' Home.
Scan now, because other Wechaty Go developers want to talk with you too! (secret code: go wechaty)
The World's Shortest Go ChatBot: 7 lines of Code
package main
import (
"fmt"
"github.com/wechaty/go-wechaty/wechaty"
"github.com/wechaty/go-wechaty/wechaty-puppet/schemas"
"github.com/wechaty/go-wechaty/wechaty/user"
)
func main() {
wechaty.NewWechaty().
OnScan(func(context *wechaty.Context, qrCode string, status schemas.ScanStatus, data string) {
fmt.Printf("Scan QR Code to login: %s\nhttps://wechaty.github.io/qrcode/%s\n", status, qrCode)
}).
OnLogin(func(context *wechaty.Context, user *user.ContactSelf) {
fmt.Printf("User %s logined\n", user)
}).
OnMessage(func(context *wechaty.Context, message *user.Message) {
fmt.Printf("Message: %s\n", message)
}).DaemonStart()
}
Go Wechaty Developing Plan
We already have Wechaty in TypeScript, It will be not too hard to translate the TypeScript(TS) to Go 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 a ecosystem of Wechaty in TypeScript, so we will not have to implement everything in Go, especially, in the Feb 2020, we have finished the @chatie/grpc service abstracting module with the wechaty-puppet-service implmentation.
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 (Go)
.
+--------------------------+ +--------------------------+
| | | |
| Wechaty (TypeScript) | | Wechaty (Go) |
| | | |
+--------------------------+ +--------------------------+
+-------------------------------------------------------+
| Wechaty Puppet Service |
| |
| (wechaty-puppet-service) |
+-------------------------------------------------------+
+--------------------- @chatie/grpc ----------------------+
+-------------------------------------------------------+
| Wechaty Puppet Abstract |
| |
| (wechaty-puppet) |
+-------------------------------------------------------+
+--------------------------+ +--------------------------+
| Pad Protocol | | Web Protocol |
| | | |
| wechaty-puppet-padplus | |(wechaty-puppet-puppeteer)|
+--------------------------+ +--------------------------+
+--------------------------+ +--------------------------+
| Windows Protocol | | Mac Protocol |
| | | |
| (wechaty-puppet-windows) | | (wechaty-puppet-macpro) |
+--------------------------+ +--------------------------+
Example: How to Translate TypeScript to Go
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 Go in Wechaty Way:
Image Class Source Code
- TypeScript: https://github.com/wechaty/wechaty/blob/master/src/user/image.ts
- Go: https://github.com/wechaty/go-wechaty/blob/master/src/wechaty/user/image.go
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 Go at the same time.
To-do List
- TS: TypeScript
- SLOC: Source Lines Of Code
Wechaty Internal Modules
- Class Wechaty
- TS SLOC(1160): https://github.com/wechaty/wechaty/blob/master/src/wechaty.ts
- Code
- Unit Tests
- Documentation
- Class Contact
- TS SLOC(804): https://github.com/wechaty/wechaty/blob/master/src/user/contact.ts
- Code
- Unit Tests
- Documentation
- Class ContactSelf
- TS SLOC(199): https://github.com/wechaty/wechaty/blob/master/src/user/contact-self.ts
- Code
- Unit Tests
- Documentation
- Class Message
- TS SLOC(1054): https://github.com/wechaty/wechaty/blob/master/src/user/message.ts
- Code
- Unit Tests
- Documentation
- Class Room
- TS SLOC(1194): https://github.com/wechaty/wechaty/blob/master/src/user/room.ts
- Code
- Unit Tests
- Documentation
- Class Image
- TS SLOC(60): https://github.com/wechaty/wechaty/blob/master/src/user/image.ts
- Code
- Unit Tests
- Documentation
- Class Accessory
- TS SLOC(179): https://github.com/wechaty/wechaty/blob/master/src/accessory.ts
- Code
- Unit Tests
- Documentation
- Class Config
- TS SLOC(187): https://github.com/wechaty/wechaty/blob/master/src/config.ts
- Code
- Unit Tests
- Documentation
- Class Favorite
- TS SLOC(52): https://github.com/wechaty/wechaty/blob/master/src/user/favorite.ts
- Code
- Unit Tests
- Documentation
- Class Friendship
- TS SLOC(417): https://github.com/wechaty/wechaty/blob/master/src/user/friendship.ts
- Code
- Unit Tests
- Documentation
- Class MiniProgram
- TS SLOC(70): https://github.com/wechaty/wechaty/blob/master/src/user/mini-program.ts
- Code
- Unit Tests
- Documentation
- Class RoomInvitation
- TS SLOC(317): https://github.com/wechaty/wechaty/blob/master/src/user/room-invitation.ts
- Code
- Unit Tests
- Documentation
- Class Tag
- TS SLOC(190): https://github.com/wechaty/wechaty/blob/master/src/user/tag.ts
- Code
- Unit Tests
- Documentation
- Class UrlLink
- TS SLOC(107): https://github.com/wechaty/wechaty/blob/master/src/user/url-link.ts
- Code
- Unit Tests
- Documentation
Wechaty External Modules
- Class FileBox
- TS SLOC(638): https://github.com/huan/file-box/blob/master/src/file-box.ts
- Code
- Unit Tests
- Documentation
- Class MemoryCard
- TS SLOC(376): https://github.com/huan/memory-card/blob/master/src/memory-card.ts
- Code
- Unit Tests
- Documentation
- Class WechatyPuppet
- TS SLOC(1115): https://github.com/wechaty/wechaty-puppet/blob/master/src/puppet.ts
- Code
- Unit Tests
- Documentation
- Class WechatyPuppetService
- TS SLOC(909): https://github.com/wechaty/wechaty-puppet-service/blob/master/src/client/puppet-service.ts
- Code
- Unit Tests
- Documentation
Usage
WIP...
Requirements
- Go 1.14+
Install
# go get wechaty
go get github.com/wechaty/go-wechaty
Development
make install
make test
See Also
- Learn Go in 12 Minutes
- How to Write Go Code
- Journey from OO language to Golang - Sergey Kibish @DevFest Switzerland 2018
- The Go Blog - Publishing Go Modules
- Effective Go
Golang for Node.js Developer
- Golang for Node.js Developers - Examples of Golang examples compared to Node.js for learning
- Learning Go as a Node.js Developer
- Golang Tutorial for Node.js Developers
History
master
v0.4 (Jun 19, 2020)
Go Wechaty Scala Wechaty BETA Released!
Read more from our Multi-language Wechaty Beta Release event from our blog:
v0.1 (Apr 03 2020)
- Welcome our second and third Go Wechaty contributors:
- Bojie LI (李博杰) https://github.com/SilkageNet #9
- Chaofei DING (丁超飞) https://github.com/dchaofei #20
- Enable GitHub Actions
- Add Makefile for easy developing
- Re-structure module directories: from
src/wechaty
towechaty
- Rename example bot to
examples/ding-dong-bot.go
v0.0.1 (Mar 12, 2020)
- Project created.
- Welcome our first Go Wechaty contributor:
- Xiaoyu DING (丁小雨) https://github.com/dingdayu #2
Related Projects
- Wechaty - Conversatioanl AI Chatot SDK for Wechaty Individual Accounts (TypeScript)
- Python Wechaty - Python WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Python)
- Go Wechaty - Go WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Go)
- Java Wechaty - Java WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Java)
- Scala Wechaty - Scala WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (Scala)
Badge
[![Wechaty in Go](https://img.shields.io/badge/Wechaty-Go-7de)](https://github.com/wechaty/go-wechaty)
Contributors
- @SilkageNet - Bojie LI (李博杰)
- @huan - Huan LI (李卓桓)
Creators
Copyright & License
- Code & Docs © 2020 Wechaty Contributors https://github.com/wechaty
- Code released under the Apache-2.0 License
- Docs released under Creative Commons