Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@re-ai/wechaty-puppet-gewe

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@re-ai/wechaty-puppet-gewe

GeWe Puppet for Wechaty

latest
npmnpm
Version
0.2.11
Version published
Maintainers
1
Created
Source

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';

// 创建 Puppet 实例
const puppet = new PuppetGeWe({
  name: 'gewe-bot',
  token: '你的GeWe Token',
  webhookUrl: 'http://your-domain.com',
  webhookPort: 8878, // 如果有公网地址,可以设置webhook
  debug: true, // 开启调试模式
  
  // SQLite 配置(可选)
  sqliteConfig: {
    dbPath: './data', // 数据库文件存储目录,会自动添加wxid作为文件名
    useWAL: true, // 启用WAL模式提高性能
    inMemory: false // 是否使用内存数据库(仅用于测试)
  },
});

// 创建 Wechaty 实例
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());

  // 如果收到 "ping",回复 "pong"
  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);

配置选项

选项类型必填说明
tokenstringGeWe API 访问 token
appIdstring保存的appId,用于重复登录
regionIdstring微信登录地区ID,默认为440000(广东省)
webhookUrlstringWebhook 回调地址,用于接收 GeWe 平台的事件通知
webhookPortnumberWebhook 服务器端口,默认为 8878
timeoutnumberAPI 请求超时时间(毫秒),默认为 30000
retriesnumberAPI 请求重试次数,默认为 3
debugboolean是否开启调试模式,默认为 false
sqliteConfigobjectSQLite 数据库配置,详见下表

SQLite 配置选项

选项类型必填说明
dbPathstring数据库文件路径,默认为 './gewe-store.db'
useWALboolean是否启用WAL模式,默认为 true
inMemoryboolean是否在内存中运行数据库(用于测试),默认为 false

功能

  • 消息收发(文本、图片、文件等)
  • 联系人管理
  • 群组管理
  • 媒体文件处理
  • 好友请求处理

开发

# 安装依赖
npm install

# 开发模式运行
npm run dev

# 构建
npm run build

# 运行示例
npm start

注意事项

  • 请使用正规注册且已实名认证的微信账号
  • 避免频繁切换登录设备
  • 不要使用本项目进行违规操作,以免封号
  • 合理控制消息发送频率
  • 避免大量相同内容的消息

许可证

ISC

Keywords

wechaty

FAQs

Package last updated on 17 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts