Convert Figma logo to code with AI

wangrongding logowechat-bot

🤖一个基于 WeChaty 结合 OpenAi ChatGPT / Kimi / 讯飞等Ai服务实现的微信机器人 ,可以用来帮助你自动回复微信消息,或者管理微信群/好友,检测僵尸粉等...

5,013
718
5,013
73

Top Related Projects

ChatGPT for wechat https://github.com/AutumnWhj/ChatGPT-wechat-bot

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT4.0/ Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。

Use ChatGPT On Wechat via wechaty

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。

Quick Overview

Wechat-bot is an open-source project that enables users to create a WeChat bot powered by ChatGPT. It allows for automated responses and interactions within WeChat, leveraging the capabilities of AI language models to enhance communication experiences.

Pros

  • Integrates ChatGPT with WeChat, providing intelligent automated responses
  • Supports various message types including text, images, and voice messages
  • Offers customizable features and configurations to suit different use cases
  • Provides a user-friendly interface for managing and monitoring the bot

Cons

  • Requires some technical knowledge to set up and configure
  • May be subject to WeChat's policies and restrictions on automated accounts
  • Potential privacy concerns when handling user conversations with AI
  • Limited documentation in English, which may pose challenges for non-Chinese speakers

Getting Started

  1. Clone the repository:

    git clone https://github.com/wangrongding/wechat-bot.git
    
  2. Install dependencies:

    cd wechat-bot
    npm install
    
  3. Configure the bot by editing the config.js file with your OpenAI API key and other settings.

  4. Start the bot:

    npm start
    
  5. Scan the QR code with your WeChat account to log in and activate the bot.

Competitor Comparisons

ChatGPT for wechat https://github.com/AutumnWhj/ChatGPT-wechat-bot

Pros of ChatGPT-wechat-bot

  • Supports multiple OpenAI models, including GPT-3.5-turbo and GPT-4
  • Implements a token counting mechanism to manage API usage
  • Offers more customization options for bot responses and behavior

Cons of ChatGPT-wechat-bot

  • Less active development and fewer contributors
  • Lacks some advanced features like voice message support
  • May require more setup and configuration

Code Comparison

ChatGPT-wechat-bot:

async def chatgpt(msg):
    token_count = count_tokens(msg)
    if token_count > MAX_TOKENS:
        return "Message too long, please reduce the length."
    response = await openai.ChatCompletion.acreate(
        model=OPENAI_MODEL,
        messages=[{"role": "user", "content": msg}],
        max_tokens=MAX_TOKENS,
    )
    return response.choices[0].message.content

wechat-bot:

async function chatgpt(content) {
  const response = await openai.createCompletion({
    model: "text-davinci-003",
    prompt: content,
    temperature: 0.9,
    max_tokens: 1500,
    top_p: 1,
    frequency_penalty: 0.0,
    presence_penalty: 0.6,
  });
  return response.data.choices[0].text;
}

The code comparison shows that ChatGPT-wechat-bot uses the newer ChatCompletion API and implements token counting, while wechat-bot uses the older Completion API with more customizable parameters.

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT4.0/ Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。

Pros of chatgpt-on-wechat

  • More comprehensive documentation, including detailed setup instructions and configuration options
  • Supports multiple AI models beyond ChatGPT, such as Azure, Claude, and Wenxin
  • Offers advanced features like voice messages, image generation, and role-playing

Cons of chatgpt-on-wechat

  • More complex setup process due to additional dependencies and configuration options
  • Potentially higher resource usage and slower performance due to additional features
  • May require more frequent updates to maintain compatibility with multiple AI models

Code Comparison

wechat-bot:

async def on_message(msg: Message):
    if msg.type() == MessageType.TEXT:
        response = await get_chat_gpt_response(msg.text())
        await msg.say(response)

chatgpt-on-wechat:

async def handle_message(msg: Message):
    if msg.type == MessageType.Text:
        context = Context(type=ContextType.TEXT, content=msg.content)
        reply = await bot.reply_text(context)
        await msg.reply(reply)

Both repositories implement similar message handling logic, but chatgpt-on-wechat uses a more abstracted approach with a Context object and dedicated reply methods for different message types.

Use ChatGPT On Wechat via wechaty

Pros of wechat-chatgpt

  • More active development with frequent updates and bug fixes
  • Supports multiple OpenAI models, including GPT-3.5 and GPT-4
  • Includes features like message history and conversation context management

Cons of wechat-chatgpt

  • More complex setup process due to additional dependencies
  • Requires OpenAI API key, which may have associated costs
  • May have higher resource usage due to advanced features

Code Comparison

wechat-bot:

const { WechatyBuilder } = require('wechaty');
const bot = WechatyBuilder.build();
bot.on('message', async (message) => {
  // Simple message handling
});

wechat-chatgpt:

import { WechatyBuilder } from 'wechaty';
import { ChatGPTBot } from './bot.js';
const bot = WechatyBuilder.build();
const chatGPTBot = new ChatGPTBot();
bot.on('message', async (message) => {
  // Advanced message handling with ChatGPT integration
});

The code comparison shows that wechat-chatgpt incorporates a dedicated ChatGPTBot class, indicating more sophisticated integration with OpenAI's models. wechat-bot, on the other hand, has a simpler structure, which may be easier to understand and modify for basic use cases.

Both projects aim to create WeChat bots, but wechat-chatgpt offers more advanced features at the cost of increased complexity. The choice between the two depends on the specific requirements of the user, such as the need for advanced AI capabilities versus simplicity and ease of setup.

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。

Pros of ChatGPT-Next-Web

  • More versatile and feature-rich web interface for ChatGPT interactions
  • Supports multiple languages and themes, enhancing user experience
  • Offers a self-hosted solution with customization options

Cons of ChatGPT-Next-Web

  • Requires more setup and configuration compared to wechat-bot
  • May have higher resource requirements for hosting and running

Code Comparison

ChatGPT-Next-Web (Next.js component):

export function Avatar(props: AvatarProps) {
  return (
    <div className={styles.avatar + " " + props.className}>
      {props.model && (
        <div className={styles["avatar-title"]}>
          {props.model.name.toLowerCase().includes("gpt-4")
            ? "GPT-4"
            : "GPT-3.5"}
        </div>
      )}
      <div className={styles["avatar-body"]}>
        {props.role === "assistant" && <BotIcon />}
        {props.role === "user" && <PersonIcon />}
      </div>
    </div>
  );
}

wechat-bot (Node.js bot logic):

async function onMessage(msg) {
  const talker = msg.talker();
  const text = msg.text();
  const room = msg.room();
  if (room) {
    const topic = await room.topic();
    console.log(`Group: ${topic} talker: ${talker.name()} content: ${text}`);
  } else {
    console.log(`talker: ${talker.name()} content: ${text}`);
  }
}

These code snippets highlight the different focus areas of each project: ChatGPT-Next-Web emphasizes UI components for a web interface, while wechat-bot concentrates on handling WeChat messages in a Node.js environment.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

WeChat Bot

一个 基于 chatgpt + wechaty 的微信机器人

可以用来帮助你自动回复微信消息,或者管理微信群/好友.

简单,好用,2分钟(4 个步骤) 就能玩起来了。🌸 如果对您有所帮助,请点个 Star ⭐️ 支持一下。

wangrongding%2Fwechat-bot | Trendshift

贡献者们

欢迎大家提交 PR 接入更多的 ai 服务(比如扣子等...),积极贡献更好的功能实现,让 wechat-bot 变得更强!

使用前需要配置的 AI 服务(目前支持 6 种,可任选其一)

  • 302.AI

    AI聚合平台,有套壳GPT的API,也有其他模型,点这里可以添加API,添加之后把API KEY配置到.env里,如下,MODEL可以自行选择配置

    _302AI_API_KEY = 'xxxx'
    _302AI_MODEL= 'gpt-4o-mini'
    

    由于openai充值需要国外信用卡,流程比较繁琐,大多需要搞国外虚拟卡,手续费也都不少,该平台可以直接支付宝,算是比较省事的,注册填问卷可领1刀额度,后续充值也有手续费,用户可自行酌情选择。

  • deepseek 获取自己的 api key,地址戳这里 👉🏻 :deepseek 开放平台
    将获取到的api key填入 .evn 文件中的 DEEPSEEK_FREE_TOKEN 中。

  • 科大讯飞

    新增科大讯飞,去这里申请一个 key:科大讯飞,每个模型都有 200 万的免费 token ,感觉很难用完。
    注意: 讯飞的配置文件几个 key,别填反了,很多人找到我说为什么不回复,都是填反了。
    而且还有一个好处就是,接口不会像 Kimi 一样限制请求频次,相对来说稳定很多。
    服务出错可参考: issues/170, issues/180

  • Kimi (请求限制较严重)

    可以去 : kimi apikey 获取你的 key
    最近比较忙,大家感兴趣可以提交 PR,我会尽快合并。目前 Kimi 刚刚集成,还可以实现上传文件等功能,然后有其它较好的服务也可以提交 PR 。

  • ChatGPT

    先获取自己的 api key,地址戳这里 👉🏻 :创建你的 api key

    注意:这个是需要去付费购买的,很多人过来问为什么请求不通,请确保终端走了代理,并且付费购买了它的服务

    # 执行下面命令,拷贝一份 .env.example 文件为 .env
    cp .env.example .env
    # 填写完善 .env 文件中的内容
    OPENAI_API_KEY='你的key'
    
  • dify

    地址:dify, 创建你的应用之后, 获取到你的 api key 之后, 填写到 .env 文件中即可, 也支持私有化部署dify版本

    # 执行下面命令,拷贝一份 .env.example 文件为 .env
    cp .env.example .env
    # 填写完善 .env 文件中的内容
    DIFY_API_KEY='你的key'
    # 如果需要私有化部署,请修改.env中下面的配置
    # DIFY_URL='https://[你的私有化部署地址]'
    
  • 其他
    (待实践)理论上使用 openAI 格式的 api,都可以使用,在 env 文件中修改对应的 api_key、model、proxy_url 即可。

API资源/平台收录

赞助商

Hi

302.AI 是一个汇集全球顶级 AI 的自助平台,按需付费,零月费,零门槛使用各种类型 AI。 产品链接 | 网站介绍

目前该项目流量较大,已经上过 27 次 Github Trending 榜,如果您的公司或者产品需要推广,可以在下方二维码处联系我,我会在项目中加入您的广告,帮助您的产品获得更多的曝光。

开发/使用

检查好自己的开发环境,确保已经安装了 nodejs , 版本需要满足 Node.js >= v18.0 ,版本太低会导致运行报错,最好使用 LTS 版本。

  1. 安装依赖

安装依赖时,大陆的朋友推荐切到 taobao 镜像源后再安装,命令:
npm config set registry https://registry.npmmirror.com
想要灵活切换,推荐使用我的工具 👉🏻 prm-cli 快速切换。

# 安装依赖
npm i
# 推荐用 yarn 吧,npm 安装有时会遇到 wechaty 内部依赖安装失败的问题
yarn
  1. 运行服务
# 启动服务
npm run dev # 或者 npm run start
# 启动服务
yarn dev # 或者 yarn start

然后就可以扫码登录了,然后根据你的需求,自己修改相关逻辑文件。

为了兼容 docker 部署,避免不必要的选择交互,新增指定服务运行

# 运行指定服务 ( 目前支持 ChatGPT | Kimi | Xunfei )
npm run start -- --serve Kimi
# 交互选择服务,仍然保持原有的逻辑
npm run start
  1. 测试

安装完依赖后,运行 npm run dev 前,可以先测试下 openai 的接口是否可用,运行 npm run test 即可。

遇到 timeout 问题需要自行解决。(一般就是代理未成功,或者你的梯子限制了调 openai api 的服务)

你要修改的

很多人说运行后不会自动收发信息,不是的哈,为了防止给每一条收到的消息都自动回复(太恐怖了),所以加了限制条件。

你要把下面提到的地方自定义修改下。

  • 群聊,记得把机器人名称改成你自己微信号的名称,然后添加对应群聊的名称到白名单中,这样就可以自动回复群聊消息了。
  • 私聊,记得把需要自动回复的好友名称添加到白名单中,这样就可以自动回复私聊消息了。
  • 更深入的可以通过修改 src/wechaty/sendMessage.js 文件来满足你自己的业务场景。(大多人反馈可能无法自动回复,也可以通过调试这个文件来排查具体原因)

在.env 文件中修改你的配置即可,示例如下

# 白名单配置
#定义机器人的名称,这里是为了防止群聊消息太多,所以只有艾特机器人才会回复,
#这里不要把@去掉,在@后面加上你启动机器人账号的微信名称
BOT_NAME=@可乐
#联系人白名单
ALIAS_WHITELIST=微信名1,备注名2
#群聊白名单
ROOM_WHITELIST=XX群1,群2
#自动回复前缀匹配,文本消息匹配到指定前缀时,才会触发自动回复,不配或配空串情况下该配置不生效(适用于用大号,不期望每次被@或者私聊时都触发自动回复的人群)
#匹配规则:群聊消息去掉${BOT_NAME}并trim后进行前缀匹配,私聊消息trim后直接进行前缀匹配
AUTO_REPLY_PREFIX=''

可以看到,自动回复都是基于 chatgpt 的,记得要开代理,或者填写代理地址。

常见问题

可以进交流群,一起交流探讨相关问题和解决方案,添加的时候记得备注来意。(如果项目对你有所帮助,也可以请我喝杯咖啡 ☕️ ~)

运行报错等问题

首先你需要做到以下几点:

  • 拉取最新代码,重新安装依赖(删除 lock 文件,删除 node_modules)

  • 安装依赖时最好不要设置 npm 镜像

  • 遇到 puppeteer 安装失败设置环境变量:

    # Mac
    export PUPPETEER_SKIP_DOWNLOAD='true'
    
    # Windows
    SET PUPPETEER_SKIP_DOWNLOAD='true'
    
  • 确保你们的终端走了代理 (开全局梯子,或者手动设置终端走代理)

    # 设置代理
    export https_proxy=http://127.0.0.1:你的代理服务端口号;export http_proxy=http://127.0.0.1:你的代理服务端口号;export all_proxy=socks5://127.0.0.1:你的代理服务端口号
    # 然后再执行 npm run test
    npm run test
    

  • 确保你的 openai key 有余额

  • 配置好 .env 文件

  • 执行 npm run test 能成功拿到 openai 的回复

  • 执行 npm run dev 愉快的玩耍吧~ 🎉

也可以参考这条 issue

  • 怎么玩? 完成自定义修改后,群聊时,在白名单中的群,有人 @ä½  时会触发自动回复,私聊中,联系人白名单中的人发消息给你时会触发自动回复。
  • 运行报错?检查 node 版本是否符合,如果不符合,升级 node 版本即可,检查依赖是否安装完整,如果不完整,大陆推荐切换下 npm 镜像源,然后重新安装依赖即可。(可以用我的 prm-cli 工具快速切换)
  • 调整对话模式?可以修改openai/index.js ,具体可以根据官方文档给出的示例(非常多,自己对应调整参数即可) :https://beta.openai.com/examples

使用 Docker 部署

$ docker build . -t wechat-bot

$ docker run -d --rm --name wechat-bot -v $(pwd)/.env:/app/.env wechat-bot

Star History Chart

该项目于 2023/2/13 日成为 Github Trending 榜首。

Star History Chart

License

MIT.