Wechaty restful api

本文介绍如何在微信个人版机器人停用后,利用WeChaty替代方案继续使用。文章详细说明了安装配置步骤,并提供了基于Koa2实现RESTful API的示例,以便通过其他语言调用机器人。此外,还分享了一个温度预报服务的实际应用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This article will explain why I started to use wechaty, made the restful api wrapping the bot and what I would do as the next step.

1. Why I started to use wechaty

wechat individual bot has been decommissioned since 2019. The wechat web reject the login using QRCode. To continue to use the bot, I tried a lot of ways and finally find the alternative — wechaty(The solution wechat enterprise provided ) https://wechaty.js.org/docs/api/message

2. How to use wechaty for bot

There are only three steps to make one simplest bot.

2.1 Install enterprise wechat in the smart phone

2.2 Apply one 15-days trial token from wechaty

Please refer to this page to get the token https://github.com/wechaty/wechaty

2.3 Write the test code as below

Now you can send first message through bot to one account or group. Please refer to the repository https://github.com/luyomo/wechaty-api

3. Prepare restful api for wechaty robot

Because I am not so familiar with the nodejs and want to use other languages to implement all kinds of services, I decided to make one API service to wrap the robot. I chose the Koa2 as the api module to publish bot and implemented the below APIs.

3.1 Publish mode

3.1.1 send chat to human

curl -X POST -H ‘Content-Type: application/json’ [Context: “http://127.0.0.1:3000/contact/contactName”] — data ‘{“data”:”Hello world. I am bot”}’

3.1.2 send chat to room

curl -X POST -H ‘Content-Type: application/json’ [Context: “http://127.0.0.1:3000/room/roomName”] — data ‘{“data”:”Hello world. I am bot”}’

3.1.3 send chat to group(map the chinese to english group name)

curl -X POST -H ‘Content-Type: application/json’ [Context: “http://127.0.0.1:3000/group/groupName”] — data ‘{“data”:”Hello world. I am bot”}’

The reason I added this group because the curl does not support the Chinese language. So use the maps to resolve it.

3.2 interactive mode

Last is to make bot to reply: Now only prepare the ping to show whether the bot service is active or not.

4 First service — Temperature forecast

Extract the temperature info from api.openweathermap.org and send to my wechat regularly. This only saved my time to browse the web every morning.

5. Next to do

5.1 Redirect the line message to wechat

This is my wife’s request. She always missed important messages from line since she use wechat mostly. She wants the bot to help her.

5.2 Use gmail api to send message if the email meets some conditions.(From or Subject)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值