- nodejs 实现一个会自动聊天的机器人
- 前端也能实现可以自动聊天、管理群聊、防撤回的微信机器人 阿吧阿吧阿吧
- 建议使用 node 16.x.x 往上
先安装要用到的包
npm i wechaty -S npm i wechaty-puppet-padplus -S npm i wechaty-puppet-wechat -S npm i qrcode-terminal -S
|
引入
import { WechatyBuilder } from "wechaty"; import QrcodeTerminal from "qrcode-terminal";
|
创建实例 生成二维吗登录
const bot = WechatyBuilder.build({ name: "puppet-wechat", puppetOptions: { uos: true }, puppet: "wechaty-puppet-wechat" });
bot.on("scan", (qrcode: any, status: any) => { console.log(`Scan QR Code to login: ${status}\n`); QrcodeTerminal.generate(qrcode, { small: true }); });
|
登陆成功
bot.on('login', (user) => { }
bot.on('message', (msg) => { let room = msg.room() if(room) let topic = room.topic() const contact = msg.talker() const contactName = contact.name() const text = msg.text()
room.say('...') contact.say('...') }
|
想回复图片的话可以用这个
import { FileBox } from "file-box";
const fileBox = FileBox.fromUrl("图片的URL"); room.say(fileBox); or; contact.say(fileBox);
|
好了 这样就可以玩了
想要会自动聊天的话 可以去接入第三方的 API 比如图灵机器人之类的接口
官方文档:链接