wechat-to-anything 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cli/bridge.mjs +2 -2
- package/cli/weixin.mjs +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ def chat(request):
|
|
|
141
141
|
return {"choices": [{"message": {"role": "assistant", "content": reply}}]}
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
>
|
|
144
|
+
> 示例:[examples/image-test.mjs](examples/image-test.mjs) · [examples/voice-test.mjs](examples/voice-test.mjs)
|
|
145
145
|
|
|
146
146
|
## 凭证
|
|
147
147
|
|
package/cli/bridge.mjs
CHANGED
|
@@ -292,8 +292,8 @@ export async function start(agents, defaultAgent) {
|
|
|
292
292
|
|
|
293
293
|
// 检查回复是否包含 [audio:path/url]
|
|
294
294
|
const audioMatch = reply.match(/\[audio:(.*?)\]/);
|
|
295
|
-
//
|
|
296
|
-
const imageMatch = reply.match(/!\[.*?\]\((https
|
|
295
|
+
// 检查回复是否包含图片(markdown 格式,支持 URL 和 data URI)
|
|
296
|
+
const imageMatch = reply.match(/!\[.*?\]\(((?:https?:\/\/|data:image\/)[^\s)]+)\)/);
|
|
297
297
|
|
|
298
298
|
if (audioMatch) {
|
|
299
299
|
const audioSrc = audioMatch[1];
|
package/cli/weixin.mjs
CHANGED
|
@@ -192,10 +192,16 @@ export async function sendMessage(token, to, text, contextToken) {
|
|
|
192
192
|
export async function sendImageByUrl(token, to, contextToken, imageUrl) {
|
|
193
193
|
const { writeFile: wf } = await import("node:fs/promises");
|
|
194
194
|
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
|
|
195
|
+
// 获取图片数据
|
|
196
|
+
let buf;
|
|
197
|
+
if (imageUrl.startsWith("data:")) {
|
|
198
|
+
const b64 = imageUrl.split(",")[1];
|
|
199
|
+
buf = Buffer.from(b64, "base64");
|
|
200
|
+
} else {
|
|
201
|
+
const resp = await fetch(imageUrl);
|
|
202
|
+
if (!resp.ok) throw new Error(`图片下载失败: ${resp.status}`);
|
|
203
|
+
buf = Buffer.from(await resp.arrayBuffer());
|
|
204
|
+
}
|
|
199
205
|
const tmpPath = "/tmp/wxta_image_send.jpg";
|
|
200
206
|
await wf(tmpPath, buf);
|
|
201
207
|
|