Coder Social home page Coder Social logo

wangrongding / wechat-bot Goto Github PK

View Code? Open in Web Editor NEW
4.7K 36.0 685.0 299 KB

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

License: MIT License

JavaScript 95.36% Dockerfile 4.64%
wechat wechatbot chatgpt openai wechaty

wechat-bot's Introduction

WeChat Bot

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

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

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

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

  • 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'
  • 其他
    (待实践)理论上使用 openAI 格式的 api,都可以使用,在 env 文件中修改对应的 api_key、model、proxy_url 即可。

赞助商

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

可以看到,自动回复都是基于 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

贡献者们

欢迎大家积极贡献更好的功能实现,让 wechat-bot 变得更强!

Star History Chart

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

Star History Chart

License

MIT.

wechat-bot's People

Contributors

agent-fengbin avatar benature avatar exposir avatar f0ng avatar imgbotapp avatar jazzqi avatar lcsluchaoshun avatar lengsukq avatar lijxug avatar saiwas avatar wangrongding avatar yangbuyiya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechat-bot's Issues

❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️ 安装或者运行报错,先看这条 Issue。

11:01:09 ERR PuppetWeChatBridge start() exception: Error: An `executablePath` or `channel` must be specified for `puppeteer-core`
11:01:09 ERR PuppetWeChat initBridge() exception: An `executablePath` or `channel` must be specified for `puppeteer-core`
11:01:09 ERR PuppetWeChat initBridge() this.bridge.stop() rejection: Error: no page
GError: An `executablePath` or `channel` must be specified for `puppeteer-core`
    at assert (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:28:15)
    at ChromeLauncher.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:36)
    at PuppeteerNode.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:154:105)
    at PuppeteerExtra.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-extra/dist/index.cjs.js:128:41)
    at async Bridge.initBrowser (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:109:23)
    at async Bridge.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:48:28)
    at async PuppetWeChat.initBridge (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:176:13)
    at async PuppetWeChat.onStart (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:69:23)
    at async PuppetWeChat.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/state-switch/dist/esm/src/service-ctl/service-ctl.js:62:17)
    at async PuppetWeChat.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet/dist/esm/src/mixins/service-mixin.js:18:13) {
  code: 2,
  details: 'Error: An `executablePath` or `channel` must be specified for `puppeteer-core`\n' +
    '    at assert (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:28:15)\n' +
    '    at ChromeLauncher.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:36)\n' +
    '    at PuppeteerNode.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:154:105)\n' +
    '    at PuppeteerExtra.launch (/Users/I576457/Documents/chatgpt/wechat-bot/node_modules/puppeteer-extra/dist/index.cjs.js:128:41)\n' +
    '    at async Bridge.initBrowser (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:109:23)\n' +
    '    at async Bridge.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:48:28)\n' +
    '    at async PuppetWeChat.initBridge (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:176:13)\n' +
    '    at async PuppetWeChat.onStart (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:69:23)\n' +
    '    at async PuppetWeChat.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/state-switch/dist/esm/src/service-ctl/service-ctl.js:62:17)\n' +
    '    at async PuppetWeChat.start (file:///Users/I576457/Documents/chatgpt/wechat-bot/node_modules/wechaty-puppet/dist/esm/src/mixins/service-mixin.js:18:13)'
}

大家有遇到过这个问题嘛..

抱歉,这个扫码报错怎么搞啊?

03:22:42 INFO onScan: 3(undefined) Scanned
03:23:42 WARN PuppetWatchdogAgent start() reset() reason: {"data":{"code":201,"url":"https://login.weixin.qq.com/qrcode/AZpheIC7hg=="},"timeoutMilliseconds":60000}
node:events:491
throw er; // Unhandled 'error' event
^

GError: WatchdogAgent reset: lastFood: "{"data":{"code":201,"url":"https://login.weixin.qq.com/qrcode/AZpheIC7hg=="},"timeoutMilliseconds":60000}"
at Watchdog.reset (file:///home/wechat-bot/node_modules/wechaty-puppet/dist/esm/src/agents/watchdog-agent.js:45:39)
at Watchdog.emit (node:events:513:28)
at Timeout._onTimeout (file:///home/wechat-bot/node_modules/watchdog/dist/esm/src/watchdog.js:81:18)

Cannot find package 'wechaty'

PS C:\python\wechat-bot-main> npm run dev

[email protected] dev
node ./index.js

node:internal/errors:484
ErrorCaptureStackTrace(err);
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'wechaty' imported from C:\python\wechat-bot-main\src\wechaty.js
at new NodeError (node:internal/errors:393:5)
at packageResolve (node:internal/modules/esm/resolve:860:9)
at moduleResolve (node:internal/modules/esm/resolve:909:20)
at defaultResolve (node:internal/modules/esm/resolve:1124:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.12.1

运行dev程序出现找不到package‘wechaty’ 下的index.js, 可是文件已经存在路径下

root@22-7-24-0556:/volume1/docker/gpt/wechatbot# npm run dev

[email protected] dev
node ./index.js

node:internal/errors:484
ErrorCaptureStackTrace(err);
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'wechaty' imported from /volume1/docker/gpt/wechatbot/src/wechaty/index.js
at new NodeError (node:internal/errors:393:5)
at packageResolve (node:internal/modules/esm/resolve:860:9)
at moduleResolve (node:internal/modules/esm/resolve:909:20)
at defaultResolve (node:internal/modules/esm/resolve:1124:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.12.1
root@22-7-24-0556:/volume1/docker/gpt/wechatbot#

prm: command not found

[root@iZ2zedZ WeChat_Bot]# npm i prm-cli -g
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142

changed 133 packages, and audited 389 packages in 7s

26 packages are looking for funding
run npm fund for details

30 vulnerabilities (2 low, 11 moderate, 12 high, 5 critical)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix --force

Run npm audit for details.
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]# prm test
bash: prm: command not found
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]#
[root@iZ2zedZ WeChat_Bot]# prm-cli
bash: prm-cli: command not found

为什么接收到消息就报错了

🚀🚀🚀 / content 你好
file:///C:/Users/Administrator/Desktop/wechat-bot/node_modules/chatgpt/build/index.js:1
import b from"expiry-map";import{v4 as T}from"uuid";import p from"node-fetch";import{createParser as S}from"eventsource-parser";async function u(i,s){let{onMessage:e,...r}=s,t=await p(i,r),n=S(o=>{o.type==="event"&&e(o.data)});t.body.on("readable",()=>{let o;for(;(o=t.body.read())!==null;)n.feed(o.toString())})}import{remark as x}from"remark";import E from"strip-markdown";function l(i){return x().use(E).processSync(i??"").toString()}var _="accessToken",v="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",w=class{constructor(s){this._accessTokenCache=new b(10*1e3);let{sessionToken:e,markdown:r=!0,apiBaseUrl:t="https://chat.openai.com/api",backendApiBaseUrl:n="https://chat.openai.com/backend-api",userAgent:o=v}=s;if(this._sessionToken=e,this._markdown=!!r,this._apiBaseUrl=t,this._backendApiBaseUrl=n,this._userAgent=o,!this._sessionToken)throw new Error("ChatGPT invalid session token")}async getIsAuthenticated(){try{return await this.refreshAccessToken(),!0}catch{return!1}}async ensureAuth(){return await this.refreshAccessToken()}async sendMessage(s,e={}){let{conversationId:r=T(),onProgress:t}=e,n=await this.refreshAccessToken(),o={action:"next",messages:[{id:T(),role:"user",content:{content_type:"text",parts:[s]}}],model:"text-davinci-002-render",parent_message_id:r},y=${this._backendApiBaseUrl}/conversation,d="";return new Promise((A,f)=>{u(y,{method:"POST",headers:{Authorization:Bearer ${n},"Content-Type":"application/json","user-agent":this._userAgent},body:JSON.stringify(o),onMessage:m=>{var g,k;if(m==="[DONE]")return A(d);try{let c=JSON.parse(m).message;if(c){let a=(k=(g=c==null?void 0:c.content)==null?void 0:g.parts)==null?void 0:k[0];a&&(this._markdown||(a=l(a)),d=a,t&&t(a))}}catch(h){console.warn("fetchSSE onMessage unexpected error",h),f(h)}}}).catch(f)})}async refreshAccessToken(){let s=this.accessTokenCache.get();if(s)return s;try{let e=await p("https://chat.openai.com/api/auth/session",{headers:{cookie:`__Secure-next-auth.session-token=${this._sessionToken}`,"user-agent":this._userAgent}}).then(n=>n.json()),r=e==null?void 0:e.accessToken;if(!r)throw new Error("Unauthorized");let t=e==null?void 0:e.error;if(t)throw t==="RefreshAccessTokenError"?new Error("session token has expired"):new Error(t);return this.accessTokenCache.set(,r),r}catch(e){throw new Error(ChatGPT failed to refresh auth token. ${e.toString()})}}};export{w as ChatGPTAPI,l as markdownToText};

Error: ChatGPT failed to refresh auth token. FetchError: invalid json response body at https://chat.openai.com/api/auth/session reason: Unexpected token < in JSON at position 0
at w.refreshAccessToken (file:///C:/Users/Administrator/Desktop/wechat-bot/node_modules/chatgpt/build/index.js:1:2376)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async w.ensureAuth (file:///C:/Users/Administrator/Desktop/wechat-bot/node_modules/chatgpt/build/index.js:1:1081)
at async getChatGPTReply (file:///C:/Users/Administrator/Desktop/wechat-bot/src/chatgpt.js:15:3)
at async WechatyImpl.onMessage (file:///C:/Users/Administrator/Desktop/wechat-bot/src/wechaty.js:60:19)

Node.js v18.12.1

使用apikey 报错 Request failed with status code 400

如下
🚀🚀🚀 / prompt dkada
Error: Request failed with status code 400
at createError (/Users/ls/Downloads/wechat-chatgpt/wechat-bot/node_modules/openai/node_modules/axios/lib/core/createError.js:16:15)
at settle (/Users/ls/Downloads/wechat-chatgpt/wechat-bot/node_modules/openai/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/Users/ls/Downloads/wechat-chatgpt/wechat-bot/node_modules/openai/node_modules/axios/lib/adapters/http.js:322:11)
at IncomingMessage.emit (node:events:539:35)
at endReadableNT (node:internal/streams/readable:1344:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {

PuppetWeChatBridge start() exception: Error: An `executablePath` or `channel` must be specified for `puppeteer-core`

sky@raspberrypi:~/projects/wechat-bot $ npm i
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142
npm WARN deprecated [email protected]: < 18.1.0 is no longer supported

added 493 packages in 2m
sky@raspberrypi:/projects/wechat-bot $ cp .env.example .env
sky@raspberrypi:
/projects/wechat-bot $ nano .env
sky@raspberrypi:~/projects/wechat-bot $ npm run dev

[email protected] dev
node ./index.js

23:02:15 ERR PuppetWeChatBridge start() exception: Error: An executablePath or channel must be specified for puppeteer-core
23:02:15 ERR PuppetWeChat initBridge() exception: An executablePath or channel must be specified for puppeteer-core
23:02:15 ERR PuppetWeChat initBridge() this.bridge.stop() rejection: Error: no page
GError: An executablePath or channel must be specified for puppeteer-core
at assert (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:28:15)
at ChromeLauncher.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:36)
at PuppeteerNode.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:154:105)
at PuppeteerExtra.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-extra/dist/index.cjs.js:128:41)
at async Bridge.initBrowser (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:109:23)
at async Bridge.start (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:48:28)
at async PuppetWeChat.initBridge (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:176:13)
at async PuppetWeChat.onStart (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:69:23)
at async PuppetWeChat.start (file:///home/sky/projects/wechat-bot/node_modules/state-switch/dist/esm/src/service-ctl/service-ctl.js:62:17)
at async PuppetWeChat.start (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet/dist/esm/src/mixins/service-mixin.js:18:13) {
code: 2,
details: 'Error: An executablePath or channel must be specified for puppeteer-core\n' +
' at assert (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/util/assert.js:28:15)\n' +
' at ChromeLauncher.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:36)\n' +
' at PuppeteerNode.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:154:105)\n' +
' at PuppeteerExtra.launch (/home/sky/projects/wechat-bot/node_modules/puppeteer-extra/dist/index.cjs.js:128:41)\n' +
' at async Bridge.initBrowser (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:109:23)\n' +
' at async Bridge.start (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/bridge.js:48:28)\n' +
' at async PuppetWeChat.initBridge (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:176:13)\n' +
' at async PuppetWeChat.onStart (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet-wechat/dist/esm/src/puppet-wechat.js:69:23)\n' +
' at async PuppetWeChat.start (file:///home/sky/projects/wechat-bot/node_modules/state-switch/dist/esm/src/service-ctl/service-ctl.js:62:17)\n' +
' at async PuppetWeChat.start (file:///home/sky/projects/wechat-bot/node_modules/wechaty-puppet/dist/esm/src/mixins/service-mixin.js:18:13)'
}
sky@raspberrypi:~/projects/wechat-bot $

最新的貌似403forbidden了

2022.12.12
主要问题出在了认证貌似新增了,修改如下:

// 定义ChatGPT的配置
const config = {
  markdown: true, // 返回的内容是否需要markdown格式
  AutoReply: true, // 是否自动回复
  clearanceToken: dotenv.config().parsed.CHATGPT_CLEARANCE,// ChatGPT的clearance,从cookie取值
  sessionToken: dotenv.config().parsed.CHATGPT_SESSION_TOKEN, // ChatGPT的sessionToken
  userAgent: dotenv.config().parsed.CHATGPT_USER_AGENT, // User-Agent
  accessToken:dotenv.config().parsed.CHATGPT_ACCESS_TOKEN// 在用户授权情况下,访问https://chat.openai.com/api/auth/session,获取accesstoken
}

.env如下

CHATGPT_SESSION_TOKEN=''
CHATGPT_CLEARANCE=''
CHATGPT_USER_AGENT=''
CHATGPT_ACCESS_TOKEN=''

image

WARN WechatyPuppetMixin start() starting puppet ... timeout

不知为何连接超时,也没搜索到相关的问题

D:\st\chatGPT_wechat\wechat-bot> npm run dev

> [email protected] dev
> node ./index.js

19:46:44 WARN WechatyPuppetMixin start() starting puppet ... timeout
19:46:44 WARN WechatyPuppetMixin start() puppet info: Puppet<PuppetWeChat>(WechatEveryDay)
Start to log in wechat...
19:47:30 ERR PuppetWeChatBridge start() exception: TimeoutError: Navigation timeout of 60000 ms exceeded
19:47:30 ERR PuppetWeChat initBridge() exception: Navigation timeout of 60000 ms exceeded
19:47:30 WARN PuppetWeChatBridge stop() page.close() exception: Error: Protocol error: Connection closed. Most likely the page has been closed.

node镜像中运行 npm run dev 报错

我使用的node容器安装的,docker pull node
07:18:36 ERR PuppetWeChatBridge start() exception: Error: An executablePath or channel must be specified for puppeteer-core
image

ChatAPI error

ChatGPTError: ChatGPTAPI error 403
at fetchSSE (file:///D:/download/wechat-bot-main/wechat-bot-main/node_modules/chatgpt/build/index.js:80:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
statusCode: 403,
statusText: 'Forbidden',
response: Response {
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 403,
timingInfo: [Object],
cacheState: '',
statusText: 'Forbidden',
headersList: [HeadersList],
urlList: [Array],
body: [Object]
},
[Symbol(headers)]: HeadersList {
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
}
}
}

npm run dev 跑起来,二维码出不来是什么问题?

二维码出不来是什么问题?
root@22-7-24-0556:/volume1/docker/wechatbot# npm run dev

[email protected] dev
node ./index.js

20:00:21 WARN WechatyPuppetMixin start() starting puppet ... timeout
20:00:21 WARN WechatyPuppetMixin start() puppet info: Puppet(WechatEveryDay)
Start to log in wechat...
20:01:19 ERR PuppetWeChatBridge start() exception: TimeoutError: Navigation timeout of 60000 ms exceeded
20:01:19 ERR PuppetWeChat initBridge() exception: Navigation timeout of 60000 ms exceeded
20:01:19 WARN PuppetWeChatBridge stop() page.close() exception: Error: Protocol error: Connection closed. Most likely the page has been closed.

npm 7.21.1 node16.9.1 Ubuntu 22.04.1 LTS can not run, because The requested module 'wechaty' is a CommonJS module, which may not support all module.exports as named exports. Could every body tell me why?

import { WechatyBuilder, ScanStatus, log } from "wechaty";
^^^^^^^^^^^^^^
SyntaxError: Named export 'WechatyBuilder' not found. The requested module 'wechaty' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'wechaty';
const { WechatyBuilder, ScanStatus, log } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:179:5)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
at async handleMainPromise (node:internal/modules/run_main:63:12)

npm run dev issue

~/wechatbot/wechat-bot$ npm run dev

[email protected] dev /home/tz/wechatbot/wechat-bot
node ./index.js

/home/tz/wechatbot/wechat-bot/index.js:1
import "./src/wechaty/index.js";
^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: node ./index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-12-12T22_46_07_481Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR! /home/tz/.npm/_logs/2022-12-12T22_46_07_481Z-debug.log

==>

Resolved by updating to the latest version nodejs!!

ChatGPT failed to refresh auth token. Error: Unauthorized

With the ChatGPT session token get from _Secure-next-auth.session-token value, still having this issue.
Tried refresh the ChapGPT page and copy & paste the token to .env fie again, but still.

Also, is it possible to grant ChatGPT internet access to future update?

ChatGPTError: ChatGPT failed to refresh auth token. Error: 403 Forbidden

Automatic robot chat mode has been activated
(node:41132) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
ChatGPTError: ChatGPT failed to refresh auth token. Error: 403 Forbidden
at ChatGPTAPI.refreshAccessToken (file:///Users/xxxx/Documents/work/chatGPT/wechat-bot/node_modules/chatgpt/build/index.js:313:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ChatGPTAPI.ensureAuth (file:///Users/xxxx/Documents/work/chatGPT/wechat-bot/node_modules/chatgpt/build/index.js:258:12)
at async getChatGPTReply (file:///Users/xxxx/Documents/work/chatGPT/wechat-bot/src/chatgpt/index.js:14:3)
at async defaultMessage (file:///Users/xxxx/Documents/work/chatGPT/wechat-bot/src/wechaty/sendMessage.js:38:27)
at async WechatyImpl.onMessage (file:///Users/xxxx/Documents/work/chatGPT/wechat-bot/src/wechaty/index.js:47:3) {
response: Response {
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 403,
timingInfo: [Object],
cacheState: '',
statusText: 'Forbidden',
headersList: [HeadersList],
urlList: [Array],
body: [Object]
},
[Symbol(headers)]: HeadersList {
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
}
},
statusCode: 403,
statusText: 'Forbidden',
originalError: ChatGPTError: 403 Forbidden

白名单冲突

似乎设置了群聊白名单,和私聊白名单,如果私聊白名单的人在群里说话,不加@也会自动回复.

429 too many requests

Have you ever encountered this situation? how did you handle it?
response: { status: 429, statusText: 'Too Many Requests', headers: { date: 'Tue, 13 Dec 2022 07:13:47 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '206', connection: 'keep-alive', vary: 'Origin', 'x-request-id': '56ee37385e9dcd3906f9d8e61a75c58e', 'strict-transport-security': 'max-age=15724800; includeSubDomains' },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.