Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit ad5bc33

Browse files
committed
feat: 处理合并消息转发
原本收到合并消息转发的消息,会直接抛出错误,现在捕获这个错误并处理
1 parent ac1aa17 commit ad5bc33

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/service/msgUploader.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,40 @@ async function sendMsg2RecvdApi(msg) {
122122
formData.append('isMsgFromSelf', msg.self() ? '1' : '0')
123123

124124
switch (msg.type()) {
125-
case MSG_TYPE_ENUM.ATTACHMENT:
125+
case MSG_TYPE_ENUM.ATTACHMENT: {
126+
try {
127+
/**@type {import('file-box').FileBox} */
128+
//@ts-expect-errors 这里msg一定是wechaty的msg
129+
const steamFile = msg.toFileBox ? await msg.toFileBox() : msg.content()
130+
formData.append('type', 'file')
131+
let fileInfo = {
132+
// @ts-ignore
133+
ext: steamFile._name.split('.').pop() ?? '',
134+
// @ts-ignore
135+
mime: steamFile._mediaType ?? 'Unknown',
136+
// @ts-ignore
137+
filename: steamFile._name ?? 'UnknownFile'
138+
}
139+
140+
formData.append(
141+
'content',
142+
//@ts-expect-errors 需要用到私有属性
143+
steamFile.buffer /** 发送一个文件 */ ??
144+
//@ts-expect-errors 需要用到私有属性
145+
steamFile.stream /** 同一个文件转发 */,
146+
{
147+
filename: fileInfo.filename,
148+
contentType: fileInfo.mime
149+
}
150+
)
151+
} catch (e) {
152+
/** 如果 const steamFile = msg.toFileBox ? await msg.toFileBox() : msg.content() 这里执行抛出错误 */
153+
/** 则很有可能是合并消息转发 */
154+
formData.append('type', 'combineforward')
155+
formData.append('content', msg.text())
156+
}
157+
break
158+
}
126159
case MSG_TYPE_ENUM.VOICE:
127160
case MSG_TYPE_ENUM.PIC:
128161
case MSG_TYPE_ENUM.VIDEO: {

0 commit comments

Comments
 (0)