wechaty / puppet-wechat4u

Wechat4u Puppet for Wechaty
https://www.npmjs.com/package/wechaty-puppet-wechat4u
Apache License 2.0
99 stars 34 forks source link

Emoticon to file Error #81

Open Nimbly8836 opened 2 months ago

Nimbly8836 commented 2 months ago

Unofficial emoji message to fileBox error

In the file puppet-wechat4u.ts around line 675 under case PUPPET.types.Message.Emoticon, here is my solution:

      case PUPPET.types.Message.Emoticon: {
        /**
         * Emoji message
         */
        const msg = await this.wechat4u.getMsgImg(rawPayload.MsgId)
        const fileExt = await getExtensionFromBuffer(msg.data)
        const ext = fileExt?.ext || 'jpg'
        filename = `${rawPayload.MsgId}.${ext}`

        const file = FileBox.fromBuffer(
          msg.data,
          filename,
        )
        return file
      }
  "dependencies": {
    "file-type": "^16.5.4"
  },

import { fromBuffer } from "file-type";
export async function getExtensionFromBuffer(buffer: Buffer) {
  return await fromBuffer(buffer)
}