完整教程,从零开始,手把手教你实现微信 AI 机器人
为什么接入微信?
- 用户习惯:中国人都在用微信
- 便捷性:无需打开其他 App,直接在微信聊天
- 自动化:消息自动处理、定时提醒、信息查询
- 隐私:本地运行,数据不外传
前置准备
- OpenClaw 已安装
- 一个微信账号(建议小号测试)
- Node.js 18+
步骤 1:安装依赖
npm install wechaty wechaty-puppet-wechat
步骤 2:配置 OpenClaw
编辑 ~/.openclaw/config.yaml:
channels:
- name: wechat
type: wechat
enabled: true
步骤 3:创建启动脚本
const { WechatyBuilder } = require('wechaty');
const bot = WechatyBuilder.build();
bot
.on('scan', (qrcode) => {
console.log('扫码登录');
})
.on('message', async (msg) => {
const text = msg.text();
// 调用 OpenClaw 处理
const reply = await processWithOpenClaw(text);
await msg.say(reply);
});
bot.start();
常见问题
Q: 登录失败?
- 换一个微信号
- 等待 24 小时
Q: 消息回复慢?
- 检查网络连接
- 检查模型 API
进阶功能
指令系统
if (text.startsWith('/')) {
const cmd = text.slice(1);
switch (cmd) {
case 'weather': return getWeather();
case 'news': return getNews();
}
}
定时提醒
// 每天 8:00 发送早报
schedule('0 8 * * *', async () => {
await contact.say('早安!');
});
安全提醒
- 不要发敏感信息
- 使用小号测试
- 遵守微信规范
💬 有问题?评论区留言!
🎯 需要帮助?微信:yang1002378395