Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 处理合并消息转发 #219

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/service/msgUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,40 @@ async function sendMsg2RecvdApi(msg) {
formData.append('isMsgFromSelf', msg.self() ? '1' : '0')

switch (msg.type()) {
case MSG_TYPE_ENUM.ATTACHMENT:
case MSG_TYPE_ENUM.ATTACHMENT: {
try {
/**@type {import('file-box').FileBox} */
//@ts-expect-errors 这里msg一定是wechaty的msg
const steamFile = msg.toFileBox ? await msg.toFileBox() : msg.content()
formData.append('type', 'file')
let fileInfo = {
// @ts-ignore
ext: steamFile._name.split('.').pop() ?? '',
// @ts-ignore
mime: steamFile._mediaType ?? 'Unknown',
// @ts-ignore
filename: steamFile._name ?? 'UnknownFile'
}

formData.append(
'content',
//@ts-expect-errors 需要用到私有属性
steamFile.buffer /** 发送一个文件 */ ??
//@ts-expect-errors 需要用到私有属性
steamFile.stream /** 同一个文件转发 */,
{
filename: fileInfo.filename,
contentType: fileInfo.mime
}
)
} catch (e) {
/** 如果 const steamFile = msg.toFileBox ? await msg.toFileBox() : msg.content() 这里执行抛出错误 */
/** 则很有可能是合并消息转发 */
formData.append('type', 'combineforward')
formData.append('content', msg.text())
}
break
}
case MSG_TYPE_ENUM.VOICE:
case MSG_TYPE_ENUM.PIC:
case MSG_TYPE_ENUM.VIDEO: {
Expand Down