Wechaty Puppet for WeChat Official Accounts helps you use Wechaty to manage your Official Account from https://mp.weixin.qq.com.
- Provide webhook proxy out-of-the-box (powered by localtunnel)
This documentation assumes that you are familiar with Wechaty already.
If you are a newbie to Wechaty, please read the following two links first:
To use wechaty-puppet-official-account
with Wechaty, just like other puppets as well:
import { Wechaty } from 'wechaty'
import { PuppetOA } from 'wechaty-puppet-official-account'
const oa = new PuppetOA({
appId : OA_APP_ID,
appSecret : OA_APP_SECRET,
token : OA_TOKEN,
webhookProxyUrl : 'https://aeb082b9-14da-4c91-bdef-90a6d17a4z98.localtunnel.me',
})
const bot = new Wechaty({
name: 'oa-bot',
puppet: oa,
})
bot.on('message', msg => {
if (!msg.self() && msg.type() === bot.Message.Type.Text && /ding/i.test(msg.text())) {
await msg.say('dong')
}
})
await bot.start()
For the full source code, see: <examples/ding-dong-bot.ts>
That's it!
You can use environment variables to configure all of the WeChat Official Account Development Information.
Developer ID(AppID) is the developer ID, Official Account identification code, which can call Official Account API with the developer's password.
The Developer Password(AppSecret) is the one with high security to verify the identity of the Official Account developer.
The token is set by you for your server(URL) configuration.
Set WECHATY_PUPPET_OA_PORT
to your local HTTP Server port number if you have a public server that can be visited from the internet.
After setting ``WECHATY_PUPPET_OA_PORT`, the puppet will expose itself to the internet with this port for providing the HTTP service.
Set WECHATY_PUPPET_OA_WEBHOOK_PROXY_URL
to a localtunnel
supported address so that you will be able to provide the Server Address(URL) for WebHook usage with this URL.
This is the most convenient way to use this puppet because you can always provide the same URL to the WeChat Official Account platform no matter where your program is running.
Currently, you can generate this URL by yourself by:
- Generate a UUIDv4 use a generator like UUID Online Generator
- Insert your $UUID to
https://${UUID}.localtunnel.me
For example, if your UUID is aeb082b9-14da-4c91-bdef-90a6d17a4z98
, then you can use https://aeb082b9-14da-4c91-bdef-90a6d17a4z98.localtunnel.me
as WECHATY_PUPPET_OA_WEBHOOK_PROXY_URL
Learn more from localtunnel
When you start developing the WeChat Official Account, it will be very helpful with the following tools provided by Tencent:
- Apply a test Official Account with full privileges for developing
- Simulate the API calls in an online simulation tool.
测试号是扫码即可获得的微信公众号,拥有所有完整高级接口权限,测试专用。
微信公众帐号测试号申请系统入口地址:
允许开发者在平台上提交信息和服务器进行交互,并得到验证结果的在线 API 调试工具。
Address: https://mp.weixin.qq.com/debug/
- nodejs+express对微信公众号进行二次开发--接收消息,自动回复文本,图片以及代码优化
- Microsoft Azure Bot Service - Connect a bot to WeChat
- v0.9 (Oct 2021): Puppet API v0.51
- v0.7 (Sep 2021): Enable ES Module support for Node.js
- Support localtunnel service from any service provider (domains).
Initial version for Official Account.
- receive messages from users
- reply message to a user (passive mode)
- Admins
- @huan Huan
- @leochen-g Leo chen
- Contributors
- Code & Docs © 2020-now Wechaty Organization
- Code released under the Apache-2.0 License
- Docs released under Creative Commons