# ChatGPT-wechat-bot **Repository Path**: karry_ii/ChatGPT-wechat-bot ## Basic Information - **Project Name**: ChatGPT-wechat-bot - **Description**: ChatGPT-wechat-bot - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2023-02-07 - **Last Updated**: 2023-10-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

ChatGPT-wechat-bot🤖

Version License: ISC

> 几步即可获得一个基于 ChatGPT 的微信机器人 🤖。 > [English](README.md) | 中文文档 ## Support - [x] 支持上下文语境的对话。 - [x] 支持重置上下文语境,通过关键词(reset)重置对话上下文语境。 - [x] 支持在群聊@你的机器人 🤖,@机器人即可收到回复。 - [x] 支持通过关键词唤醒你的机器人,如当在群组中发送“@机器人 hello xxxx”时才会收到回复。 - [x] 支持 Docker 运行。 - [x] 支持设置重试次数,当请求 ChatGPT 错误时,会自动重试。 - [x] 捕获错误并重试。 - [ ] 其他 ## Update February 3, 2023 🔥This package no longer requires any browser hacks – it is now using the official OpenAI completions API with a leaked model ## 默认配置 ``` { // 填入你的OPENAI_API_KEY OPENAI_API_KEY: '', // 设置获取消息的重试次数 retryTimes: 3, // 在群组中设置唤醒微信机器人的关键词 groupKey: '', // 在私聊中设置唤醒微信机器人的关键词 privateKey: '', // 重置上下文的关键词,如可设置为reset resetKey: 'reset', // 开启会后收到ChatGPT的自动回复 autoReply: true, // 根据正则匹配是否自动通过好友验证 friendShipRule: /chatgpt|chat/, // 在群聊中用回复的格式进行回复 groupReplyMode: true, // 在私聊中用回复的格式进行回复 privateReplyMode: false, } ``` ## 开始设置机器人 🤖 1. 首先,需要按照以下步骤获你的 ChatGPT 的 OPENAI_API_KEY. > 获取你的 OPENAI_API_KEY: > > - 打开 [https://platform.openai.com/overview](https://platform.openai.com/overview) 并登录注册,进入网页。 ![image.png](https://cdn.nlark.com/yuque/0/2023/png/2777249/1675413138418-d5df2543-bd37-41cc-a16c-505c5a38e88d.png) ![image.png](https://cdn.nlark.com/yuque/0/2023/png/2777249/1675413190188-4cf10947-ea7f-479d-9550-0dec9d40c0e2.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0) 2. 把 OPENAI_API_KEY 填入目录`src/config.js`下的 `OPENAI_API_KEY` 中,然后在终端运行以下命令。如有需要,请在`src/config.js`中配置其它配置变量。 ```javascript // install dependencies npm i npm run dev ``` 3. 执行完之后,可以看到终端控制台输出一下信息,扫码登录即可. ![image.png](https://cdn.nlark.com/yuque/0/2022/png/2777249/1670287138908-cc898c58-6e0a-488f-ae07-ae489508c1be.png#averageHue=%23484948&clientId=uf4023d0a-0da7-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=442&id=ub5fee6b7&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1200&originWidth=1660&originalType=binary&ratio=1&rotation=0&showTitle=false&size=492370&status=done&style=none&taskId=u233d9139-1ef5-42bf-9f44-354c6565862&title=&width=612) 4. 登录成功,用另外一个微信往你扫码登录的微信发消息,你将会收到来自 ChatGPT 的回复。 ![image.png](https://cdn.nlark.com/yuque/0/2022/png/2777249/1670288278607-73beed83-1a42-42db-8404-72ba60bf2c53.png#averageHue=%234d4e4d&clientId=uf4023d0a-0da7-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=437&id=uff52651b&margin=%5Bobject%20Object%5D&name=image.png&originHeight=874&originWidth=1398&originalType=binary&ratio=1&rotation=0&showTitle=false&size=543479&status=done&style=none&taskId=ub5559ec7-30f8-4c07-a9f8-1445a659835&title=&width=699)![image.png](https://cdn.nlark.com/yuque/0/2022/png/2777249/1670288469581-470c7f45-b3db-4a7e-ab01-32b44b812668.png#averageHue=%23f2f2f2&clientId=uf4023d0a-0da7-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=230&id=u97e5b1e5&margin=%5Bobject%20Object%5D&name=image.png&originHeight=460&originWidth=1266&originalType=binary&ratio=1&rotation=0&showTitle=false&size=112172&status=done&style=none&taskId=u7d7970df-3044-4534-910c-fdb7b3d2a5b&title=&width=633) ## QA 1. If your WeChat cannot log in Please check the root directory of your project, whether there is a file —— `WechatEveryDay.memory-card`, if so, please delete it and try it again. 2. 支持的 node 版本: Node.js >= 16.8 3. 因为 ChatGPT 的长度限制,如果回复消息不完整,可以对它说"请继续" 或者 "请继续写完"。 image 4. Error: Failed to launch the browser process puppeteer refer to ``` // ubuntu sudo apt-get install chromium-browser sudo apt-get install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils ``` ## 👏🏻 欢迎一起共建 欢迎贡献你的代码以及想法 🍵。