ai-wechat-bot

ai-wechat-bot

将所有AI 产品接入你的微信,打造你个人AI 助理,帮助你解决更多生活日常。

Stars: 325

Visit
 screenshot

Gewechat is a project based on the Gewechat project to implement a personal WeChat channel, using the iPad protocol for login. It can obtain wxid and send voice messages, which is more stable than the itchat protocol. The project provides documentation for the API. Users can deploy the Gewechat service and use the ai-wechat-bot project to interface with it. Configuration parameters for Gewechat and ai-wechat-bot need to be set in the config.json file. Gewechat supports sending voice messages, with limitations on the duration of received voice messages. The project has restrictions such as requiring the server to be in the same province as the device logging into WeChat, limited file download support, and support only for text and image messages.

README:

1. gewechat

Gewechat 是基于Gewechat项目实现的微信个人号通道,使用ipad协议登录,该协议能获取到wxid,能发送语音条消息,相比itchat协议更稳定。

api文档地址为:gewechat api

首先可以简单了解 ai-wechat-bot、gewechat服务的调用关系,如下图所示

2. gewechat 服务部署教程

gewechat 服务需要自行部署,ai-wechat-bot 项目只负责对接gewechat服务,请参考下方教程部署gewechat服务。

2.1 下载镜像

感谢gewechat交流群中的大佬 @1H 重构了镜像,让gewe镜像不依赖cgroup和docker --privilege,可以在更高版本的ubuntu、debian以及macos系统上运行。

# 从阿里云镜像仓库拉取(国内)
docker pull registry.cn-chengdu.aliyuncs.com/tu1h/wechotd:alpine
docker tag registry.cn-chengdu.aliyuncs.com/tu1h/wechotd:alpine gewe

# 或从GitHub镜像仓库拉取
docker pull ghcr.io/tu1h/wechotd/wechotd:alpine
docker tag ghcr.io/tu1h/wechotd/wechotd:alpine gewe

2.2 使用docker启动

mkdir -p gewechat/data  
docker run -itd -v gewechat/data:/root/temp -p 2531:2531 -p 2532:2532 --restart=always --name=gewe gewe

2.3 使用docker compose启动

首先创建必要的数据目录:

mkdir -p gewechat/data

创建 docker-compose.yml 文件:

version: '3'
services:
  gewechat:
    image: gewe
    container_name: gewe
    volumes:
      - ./gewechat/data:/root/temp
    ports:
      - "2531:2531"
      - "2532:2532"
    restart: always

运行:

docker compose up -d

2.4 成功日志

看到如下日志,表示gewechat服务启动成功

3. 使用ai-wechat-bot对接gewechat服务

3.1 gewechat相关参数配置

在config.json中需要配置以下gewechat相关的参数:

{
    "channel_type": "gewechat"   # 通道类型,请设置为gewechat    
    "gewechat_token": "",        # gewechat服务的token,用于接口认证
    "gewechat_app_id": "",       # gewechat服务的应用ID
    "gewechat_base_url": "http://本机ip:2531/v2/api",  # gewechat服务的API基础URL
    "gewechat_callback_url": "http://本机ip:9919/v2/api/callback/collect", # 回调URL,用于接收消息
    "gewechat_download_url": "http://本机ip:2532/download", # 文件下载URL
}

参数说明:

  • gewechat_token: gewechat服务的认证token,首次登录时,可以留空,启动ai-wechat-bot服务时,会自动获取token自动保存到config.json
  • gewechat_app_id: gewechat服务分配的设备ID,首次登录时,可以留空,启动ai-wechat-bot服务时,会自动获取appid自动保存到config.json
  • gewechat_base_url: gewechat服务的API基础地址,请根据实际情况配置,如果gewechat服务与ai-wechat-bot服务部署在同一台机器上,可以配置为http://本机ip:2531/v2/api
  • gewechat_callback_url: 接收gewechat消息的回调地址,请根据实际情况配置,如果gewechat服务与ai-wechat-bot服务部署在同一台机器上,可以配置为http://本机ip:9919/v2/api/callback/collect,如无特殊需要,请使用9919端口号
  • gewechat_download_url: 文件下载地址,用于下载语音、图片等文件,请根据实际部署情况配置,如果gewechat服务与ai-wechat-bot服务部署在同一台机器上,可以配置为http://本机ip:2532/download

注意:请确保您的回调地址(callback_url),即ai-wechat-bot启动的回调服务可以被gewechat服务正常访问到。如果您使用Docker部署,需要注意网络配置,确保容器之间可以正常通信。

3.2 ai-wechat-bot相关参数配置

在config.json中需要配置以下

{
  "channel_type": "gewechat",                   # 通道类型设置为gewechat
  "model": "dify",                              # 模型名称设置为dify
  "single_chat_prefix": [""],                   # 私聊触发前缀
  "single_chat_reply_prefix": "",               # 私聊回复前缀
  "group_chat_prefix": ["@bot"],                # 群聊触发前缀
  "group_name_white_list": ["ALL_GROUP"],       # 允许响应的群组
}

3.3 启动ai-wechat-bot服务

完成上述配置后,你需要确保gewechat服务已正常启动

mvn run ai-wechat-bot.jar

启动成功后,可以看到如下日志信息,注意token和appid会自动保存到config.json,无需手动保存

3.4 利用gewechat发送语音条消息

语音相关配置如下,另外需要在dify应用中开启语音转文字以及文字转语音功能,注意语音功能需要安装ffmpeg依赖

{
  "channel_type": "gewechat",  # 通道类型设置为gewechat
  "model": "ai",    
  "speech_recognition": true,  # 是否开启语音识别
  "voice_reply_voice": true,   # 是否使用语音回复语音
  "always_reply_voice": false, # 是否一直使用语音回复
  "voice_to_text": "ai",     # 语音识别引擎
  "text_to_voice": "ai"      # 语音合成引擎
}

gewechat支持发送语音条消息,但是gewechat服务只能获取到20s以内的语音,所以你只能给bot发送20s以内的语音,而bot给你发送语音时无此限制

4. gewechat_channel 服务的限制

  1. gewechat 要求必须搭建服务到同省服务器或者电脑里方可正常使用,即登录微信的手机与gewechat服务必须在同一省
  2. gewechat 开源框架只支持下载接收到的图片,不支持下载文件
  3. gewechat_channel 目前暂时只支持接收文字消息只支持发送文字消息与图片消息,后续支持的消息类型会逐步完善
  4. 此项目仅用于个人娱乐场景,请勿用于任何商业场景

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for ai-wechat-bot

Similar Open Source Tools

For similar tasks

For similar jobs