最佳实践
Last updated
Was this helpful?
Last updated
Was this helpful?
使用TypeScript 作为开发语言,TypeScript 是强类型的JavaScript,统一typings,增强系统的可维护性。更多请查看issue 讨论:, .
使用TSLint 作为代码检查工具,为什么需要?。wechaty 的tslint 配置说明请参考。
使用 作为编译器。
文件的命名规则是小写,用-
连接所有的内容而不是空格。比如2017-10-06-wechat-pc-impactor
而不是 2017-10-06-WeChat PC Impactor
变量命名为小驼峰
写法。如 userName
而不是 user_name
。
最新版的 Wechaty Docker Image (v0.22)预装了所有的 puppet ,包括 puppeteer 和 padchat 等代码里面预设的所有.
Wechaty Docker 同时支持JavaScript 和TypeScript。因为我们使用 ts-node
运行代码,所以你不需要编译,只需要将拓展名改为.ts
即可使用TypeScript。
进一步说明:在启动的时候设置wechaty 的 name(旧版本叫profile) 来存储机器人的登陆信息,登陆后会自动生成一个*.memory-card.json
的文件,这样再次运行的时候,就不需要扫码就可以直接登陆机器人了。
我们也建议开发者在调用wechaty 方法的时候,也自行设置间隔,数值建议如下:
发送消息:1s
修改备注:10s
添加好友: 5min
自动通过好友请求:1min
持续更新中。。。
silent
error
warn
info
verbose
silly
有以下两种方式来设置LOG 的级别:
可以通过设置环境变量 `WECHATY_LOG` 的方式设置LOG的级别
在代码中设置:
docker运行的bot文件如何debug?像nodemon那样?
如何理解Wechaty 及相关Puppet 的版本号
简单回答:
次要版本号是偶数数字是生产版本。
详细回答:
数字的规则:
偶数版本,如0.8,0.12,是用于生产环境的
奇数版本,如0.11,0.13,是发布的开发版本
偶数版本 例子: (用于生产环境)
0.16.1
0.16.2
1.0.1
1.0.2
技术版本 例子: (用于开发环境)
0.15.1
0.15.2
1.1.1
1.1.2
同时,只要代码通过了Travis CI 的自动化测试,我们会发布所有版本的NPM包。
Node.js 版本高于 10
了解更多:.
为了防止微信封号,wechaty 内置了队列,详细可见:
wechaty 使用了 作为日志工具,默认打印的级别是`verbose`, brolog 共有的级别从高到低分别为:
wechaty 提供了hot-import 模块,参考:
Wechaty 根据 的规则制定版本号,并使用次要版本号来发布的版本是生产版本还是开发版本。
参考 和 , 当语义版本的次要版本号是技术的时候,意味着它是开发分支,建议不要上生产环境。
如果想了解更多:
同时支持, , 和 多个平台。windows 用户如果安装失败,请参考这篇博客:
:Memory Card is an Easy to Use Key/Value Store, with Swagger API Backend & Serialization Support.
: Brolog is Logger for Angular in Browser like Npmlog.
: Easy to Use ReactiveX Queue that Supports Delay/DelayExector/Throttle/Debounce Features Powered by RxJS.
:Pack a File into Box for easy move/transfer between servers no matter of where it is.(local, remote url, or cloud storage)
: Hot Module Replacement(HMR) for Node.js
: FlashStore is a Key-Value persistent storage with easy to use ES6 Map-like API(both Async and Sync support), powered by LevelDB and TypeScript.
: State Switch is a Monitor/Guard for Managing Your Async Operations.
: An Timer used to Detect and Recover from Malfunctions
: Hook node exit with your callback, get exit code
and signal name
from parameters
: Pure C++ Node.js LevelDB binding serving as the back-end to LevelUP