From 0b0ec7a32ad1f26498b6d7bd8b390d8260f8d69e Mon Sep 17 00:00:00 2001 From: chentianyu Date: Thu, 28 Sep 2023 09:07:04 +0800 Subject: [PATCH] Revert "[skip ci]: change cdn address" This reverts commit 8c45cef5211e355913a98eb0bb3a2f07e8ed5a28. --- .env | 2 +- README.md | 27 ++-- dockerfile | 2 +- package-lock.json | 305 +++++++++++------------------------------ package.json | 1 - src/service/webhook.js | 15 +- 6 files changed, 108 insertions(+), 244 deletions(-) diff --git a/.env b/.env index 54efbee..0d10eb1 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ PORT=3001 # 如果想自己处理收到消息的逻辑,在下面填上你的webhook地址, 默认为空 -RECVD_MSG_WEBHOOK=https://home.danielcoding.me:888/webhook-test/53f51927-9cec-447b-899a-d4a212000808 \ No newline at end of file +RECVD_MSG_WEBHOOK= \ No newline at end of file diff --git a/README.md b/README.md index 0b5c486..91828c0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [view this project on docker hub :)](https://hub.docker.com/repository/docker/dannicool/docker-wechatbot-webhook/general) -## 一、启动 +## 一、开始 ### 1. 本地调试 @@ -16,7 +16,7 @@ npm start ``` -### 2. docker 部署 +### 2. docker 启动 #### 拉取镜像 @@ -26,13 +26,10 @@ docker pull dannicool/docker-wechatbot-webhook #### 启动容器(后台常驻) -> -e RECVD_MSG_WEBHOOK 环境变量可以不填,如果你还想收消息, 可以传入 - ```bash docker run -d \ --name wcRoomBot \ -p 3001:3001 \ --e RECVD_MSG_WEBHOOK="https://example.com/your/url" \ dannicool/docker-wechatbot-webhook ``` @@ -44,11 +41,13 @@ docker logs -f wcRoomBot 找到二维码登录地址,图下 url 部分,浏览器访问,扫码登录wx -![](https://cdn.jsdelivr.net/gh/danni-cool/danni-cool@cdn/image/docker-login-wechat.png) +![](https://cdn.jsdelivr.net/gh/danni-cool/blog.danni.cool/cdn/image/docker-login-wechat.png) + +## 二、给机器人推送消息 -## 二、webhook +目前只支持 **文字** 和 **图片**,消息不支持图文自动拆分,请手动调多次 -### 1. 推消息 +### webhook格式 - Url: - Methods: `POST` @@ -61,12 +60,14 @@ docker logs -f wcRoomBot |--|--|--|--|--|--|--| | to | 会话名 | String | | N | | 发群消息填群名,发给个人填昵称 | | isRoom | 是否发的群消息 | Boolean | false | Y | | | -| type | 发送消息类型 | String || N | | 目前只支持 **文字** 和 **图片**,消息不支持图文自动拆分,请手动调多次 | +| type | 发送消息类型 | String || N | | | | content | 发送的消息 | String | | N | | 如果希望发多张图,type 指定为 img 同时,content 里填 url 以英文逗号分隔 | -### 2. 收消息 + + +## 三、更新日志 更新内容参见 [CHANGELOG](https://github.com/danni-cool/docker-wechat-roomBot/blob/main/CHANGELOG.md) diff --git a/dockerfile b/dockerfile index f5988fa..eea443d 100644 --- a/dockerfile +++ b/dockerfile @@ -14,7 +14,7 @@ RUN npm install COPY . . # 如果收消息想接入webhook -ENV RECVD_MSG_WEBHOOK= +# ENV RECVD_MSG_WEBHOOK= # 暴露端口(你的 Express 应用程序监听的端口) EXPOSE 3001 diff --git a/package-lock.json b/package-lock.json index c282024..7918579 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "dotenv": "^16.3.1", "express": "^4.18.2", - "form-data": "^4.0.0", "node-fetch-commonjs": "^3.3.2", "wechaty": "^1.20.2" }, @@ -759,200 +758,6 @@ "version": "1.1.0", "license": "BSD-3-Clause" }, - "node_modules/@swc/core": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.78.tgz", - "integrity": "sha512-y6DQP571v7fbUUY7nz5G4lNIRGofuO48K5pGhD9VnuOCTuptfooCdi8wnigIrIhM/M4zQ53m/YCMDCbOtDgEww==", - "hasInstallScript": true, - "peer": true, - "engines": { - "node": ">=10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/swc" - }, - "optionalDependencies": { - "@swc/core-darwin-arm64": "1.3.78", - "@swc/core-darwin-x64": "1.3.78", - "@swc/core-linux-arm-gnueabihf": "1.3.78", - "@swc/core-linux-arm64-gnu": "1.3.78", - "@swc/core-linux-arm64-musl": "1.3.78", - "@swc/core-linux-x64-gnu": "1.3.78", - "@swc/core-linux-x64-musl": "1.3.78", - "@swc/core-win32-arm64-msvc": "1.3.78", - "@swc/core-win32-ia32-msvc": "1.3.78", - "@swc/core-win32-x64-msvc": "1.3.78" - }, - "peerDependencies": { - "@swc/helpers": "^0.5.0" - }, - "peerDependenciesMeta": { - "@swc/helpers": { - "optional": true - } - } - }, - "node_modules/@swc/core-darwin-arm64": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.78.tgz", - "integrity": "sha512-596KRua/d5Gx1buHKKchSyHuwoIL4S1BRD/wCvYNLNZ3xOzcuBBmXOjrDVigKi1ztNDeS07p30RO5UyYur0XAA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.78.tgz", - "integrity": "sha512-w0RsD1onQAj0vuLAoOVi48HgnW6D6oBEIZP17l0HYejCDBZ+FRZLjml7wgNAWMqHcd2qNRqgtZ+v7aLza2JtBQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.78.tgz", - "integrity": "sha512-v1CpRn+H6fha1WIqmdRvJM40pFdjUHrGfhf4Ygci72nlAU41l5XimN8Iwkm8FgIwf2wnv0lLzedSM4IHvpq/yA==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.78.tgz", - "integrity": "sha512-Sis17dz9joJRFVvR/gteOZSUNrrrioo81RQzani0Zr5ZZOfWLMTB9DA+0MVlfnVa2taYcsJHJZFoAv9JkLwbzg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.78.tgz", - "integrity": "sha512-E5F8/qp+QupnfBnsP4vN1PKyCmAHYHDG1GMyPE/zLFOUYLgw+jK4C9rfyLBR0o2bWo1ay2WCIjusBZD9XHGOSA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.78.tgz", - "integrity": "sha512-iDxa+RknnTQlyy+WfPor1FM6y44ERNI2E0xiUV6gV6uPwegCngi8LFC+E7IvP6+p+yXtAkesunAaiZ8nn0s+rw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-musl": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.78.tgz", - "integrity": "sha512-dWtIYUFL5sMTE2UKshkXTusHcK8+zAhhGzvqWq1wJS45pqTlrAbzpyqB780fle880x3A6DMitWmsAFARdNzpuQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.78.tgz", - "integrity": "sha512-CXFaGEc2M9Su3UoUMC8AnzKb9g+GwPxXfakLWZsjwS448h6jcreExq3nwtBNdVGzQ26xqeVLMFfb1l/oK99Hwg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.78.tgz", - "integrity": "sha512-FaH1jwWnJpWkdImpMoiZpMg9oy9UUyZwltzN7hFwjR48e3Li82cRFb+9PifIBHCUSBM+CrrsJXbHP213IMVAyw==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.3.78", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.78.tgz", - "integrity": "sha512-oYxa+tPdhlx1aH14AIoF6kvVjo49tEOW0drNqoEaVHufvgH0y43QU2Jum3b2+xXztmMRtzK2CSN3GPOAXDKKKg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": ">=10" - } - }, "node_modules/@tokenizer/token": { "version": "0.3.0", "license": "MIT" @@ -1108,6 +913,18 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "license": "MIT" @@ -2221,9 +2038,8 @@ } }, "node_modules/file-box": { - "version": "1.5.5", - "resolved": "https://registry.npmjs.org/file-box/-/file-box-1.5.5.tgz", - "integrity": "sha512-NnR7X2KwTL0l/FFDnConXfVdR+qw9riLYwLW4xqihfTna1XBgB1Ac2wmu9T/gNVmsLZbmyZbSOOl+b5ahvAHQg==", + "version": "1.4.15", + "license": "Apache-2.0", "dependencies": { "brolog": "^1.14.2", "clone-class": "^1.0.3", @@ -2238,6 +2054,14 @@ "npm": ">=7" } }, + "node_modules/file-box/node_modules/clone-class": { + "version": "1.0.3", + "license": "Apache-2.0", + "engines": { + "node": ">=16", + "npm": ">=7" + } + }, "node_modules/file-box/node_modules/mime": { "version": "3.0.0", "license": "MIT", @@ -2345,16 +2169,15 @@ } }, "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "version": "2.5.1", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", + "combined-stream": "^1.0.6", "mime-types": "^2.1.12" }, "engines": { - "node": ">= 6" + "node": ">= 0.12" } }, "node_modules/forwarded": { @@ -5195,19 +5018,6 @@ "mime": "^1.3.4" } }, - "node_modules/wechat4u/node_modules/form-data": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", - "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, "node_modules/wechaty": { "version": "1.20.2", "license": "Apache-2.0", @@ -5263,9 +5073,8 @@ } }, "node_modules/wechaty-puppet": { - "version": "1.21.3", - "resolved": "https://registry.npmjs.org/wechaty-puppet/-/wechaty-puppet-1.21.3.tgz", - "integrity": "sha512-CkU/Q+LviLNgA0ypBloh8EWOhCBE0gXdMrIuFkacEGLz2oSJe1xnLluR1R5eQUf/d9qPn/D37uPvwb4GPq3usA==", + "version": "1.20.2", + "license": "Apache-2.0", "dependencies": { "@alloc/quick-lru": "^5.2.0", "brolog": "^1.14.2", @@ -5311,10 +5120,61 @@ "wechaty-puppet": "^1.19.1" } }, + "node_modules/wechaty-puppet-service/node_modules/file-box": { + "version": "1.5.5", + "license": "Apache-2.0", + "dependencies": { + "brolog": "^1.14.2", + "clone-class": "^1.0.3", + "jimp": "^0.16.1", + "jsqr": "^1.4.0", + "mime": "^3.0.0", + "qrcode": "^1.5.0", + "uuid": "^8.3.2" + }, + "engines": { + "node": ">=16", + "npm": ">=7" + } + }, + "node_modules/wechaty-puppet-service/node_modules/file-box/node_modules/clone-class": { + "version": "1.0.3", + "license": "Apache-2.0", + "engines": { + "node": ">=16", + "npm": ">=7" + } + }, + "node_modules/wechaty-puppet-service/node_modules/mime": { + "version": "3.0.0", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/wechaty-puppet-service/node_modules/wechaty-token": { + "version": "1.0.6", + "license": "Apache-2.0", + "dependencies": { + "brolog": "^1.14.2", + "cmd-ts": "^0.7.0", + "cockatiel": "^2.0.2", + "uuid": "^8.3.2" + }, + "bin": { + "wechaty-token": "dist/esm/bin/cli.js" + }, + "engines": { + "node": ">=16", + "npm": ">=7" + } + }, "node_modules/wechaty-puppet-wechat4u": { - "version": "1.14.5", - "resolved": "https://registry.npmjs.org/wechaty-puppet-wechat4u/-/wechaty-puppet-wechat4u-1.14.5.tgz", - "integrity": "sha512-U3BqBqjP4c1sr54/FgvbzwZgfkB+CFbwh+JhK7G08oKIE2gnQIUxKfkrt2ANgOIIaGXeely+vt2g17PgcLqjeA==", + "version": "1.14.1", + "license": "Apache-2.0", "dependencies": { "@alloc/quick-lru": "^5.2.0", "fast-xml-parser": "^3.21.1", @@ -5327,7 +5187,6 @@ "npm": ">=7" }, "peerDependencies": { - "@swc/core": "1.3.78", "wechaty-puppet": "^1.18.3" } }, diff --git a/package.json b/package.json index 808bb59..7b02176 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "dependencies": { "dotenv": "^16.3.1", "express": "^4.18.2", - "form-data": "^4.0.0", "node-fetch-commonjs": "^3.3.2", "wechaty": "^1.20.2" }, diff --git a/src/service/webhook.js b/src/service/webhook.js index 80ca244..4764f66 100644 --- a/src/service/webhook.js +++ b/src/service/webhook.js @@ -1,5 +1,5 @@ const fetch = require('node-fetch-commonjs') -const FormData = require('form-data') + const sendMsg2RecvdWebHook = async function (msg, webhookUrl) { const msgData = { room: msg.room() || '', @@ -15,12 +15,12 @@ const sendMsg2RecvdWebHook = async function (msg, webhookUrl) { switch (msg.type()) { // 图片 - case 0: case 6: msgData.type = 'img' - formData.append('data', JSON.stringify(msgData)) const steamFile = await msg.toFileBox() - formData.append('file', steamFile.buffer || new Uint8Array(steamFile.stream.buffer), { filename: 'image.jpg', contentType: 'image/jpeg' }) + const uint8Array = new Uint8Array(steamFile.stream.buffer); + formData.append('data', JSON.stringify(msgData)) + formData.append('file',new Blob([uint8Array]), 'image.jpg') break; // 纯文本 @@ -31,19 +31,20 @@ const sendMsg2RecvdWebHook = async function (msg, webhookUrl) { break; // 其他统一暂不处理 - case 5: //表情 default: passed = false break; } - // 其他消息和本人发的消息不处理 - if (!passed || msg.self) return + if(!passed) return console.log('starting fetching api: ' + webhookUrl, msg.payload) await fetch(webhookUrl, { method: 'POST', + headers: { + 'Content-Type': 'multipart/form-data', // 通常用于包含文件和其他数据 + }, body: formData }) }