Wechaty Puppet GeWe
这是一个基于 GeWe 云 API 的 Wechaty Puppet 实现,将 GeWe 开放平台的能力与 Wechaty 框架连接,使开发者可以通过统一的 Wechaty 接口操作微信。
安装
npm install @re-ai/wechaty-puppet-gewe
使用方法
import { WechatyBuilder } from 'wechaty';
import { PuppetGeWe } from '@re-ai/wechaty-puppet-gewe';
import * as qrcode from 'qrcode-terminal';
import { types } from 'wechaty-puppet';
import { FileBox } from 'file-box';
const puppet = new PuppetGeWe({
name: 'gewe-bot',
token: '你的GeWe Token',
webhookUrl: 'http://your-domain.com',
webhookPort: 8878,
debug: true,
sqliteConfig: {
dbPath: './data',
useWAL: true,
inMemory: false
},
});
const bot = WechatyBuilder.build({
name: 'gewe-bot',
puppet,
});
bot.on('scan', (qrcodeUrl: string, status: types.ScanStatus) => {
console.log(`收到二维码,状态: ${status}`);
if (qrcodeUrl) {
if (qrcodeUrl.startsWith('data:image')) {
console.log('请扫描二维码登录 (请在微信中扫码)');
} else {
qrcode.generate(qrcodeUrl, { small: true });
console.log('请扫描二维码登录 (请在微信中扫码)');
}
}
});
bot.on('login', async (user) => {
console.log(`用户 ${user.name()} (${user.id}) 已登录`);
const avatar = await user.payload?.avatar;
console.log(`用户头像: ${avatar}`);
});
bot.on('message', async (message) => {
console.log(`收到消息: ${message.text()}`, message.type());
if (message.text() === 'ping') {
await message.say('pong');
return;
}
if (message.text() === '图片') {
const fileBox = FileBox.fromUrl(
'https://wechaty.js.org/img/wechaty-logo.svg',
'wechaty-logo.svg',
);
await message.say(fileBox);
return;
}
});
bot.on("friendship", async (friendship) => {
console.log(`收到好友请求: ${friendship.hello()}`);
friendship.accept();
});
bot.start()
.then(() => console.log('机器人已启动...'))
.catch(console.error);
配置选项
token | string | 是 | GeWe API 访问 token |
appId | string | 否 | 保存的appId,用于重复登录 |
regionId | string | 否 | 微信登录地区ID,默认为440000(广东省) |
webhookUrl | string | 否 | Webhook 回调地址,用于接收 GeWe 平台的事件通知 |
webhookPort | number | 否 | Webhook 服务器端口,默认为 8878 |
timeout | number | 否 | API 请求超时时间(毫秒),默认为 30000 |
retries | number | 否 | API 请求重试次数,默认为 3 |
debug | boolean | 否 | 是否开启调试模式,默认为 false |
sqliteConfig | object | 否 | SQLite 数据库配置,详见下表 |
SQLite 配置选项
dbPath | string | 否 | 数据库文件路径,默认为 './gewe-store.db' |
useWAL | boolean | 否 | 是否启用WAL模式,默认为 true |
inMemory | boolean | 否 | 是否在内存中运行数据库(用于测试),默认为 false |
功能
- 消息收发(文本、图片、文件等)
- 联系人管理
- 群组管理
- 媒体文件处理
- 好友请求处理
开发
npm install
npm run dev
npm run build
npm start
注意事项
- 请使用正规注册且已实名认证的微信账号
- 避免频繁切换登录设备
- 不要使用本项目进行违规操作,以免封号
- 合理控制消息发送频率
- 避免大量相同内容的消息
许可证
ISC