Skip to main content

Processing files

Sending File#

import { FileBox } from 'wechaty'
const fileBox = FileBox.fromUrl('https://wechaty.js.org/img/icon.png')
await bot.say(fileBox)

Receiving File#

import { Message } from 'wechaty'
async function onMessage (message: Message) {
const fileTypeList = [
Message.Type.Attachment,
Message.Type.Audio,
Message.Type.Image,
Message.Type.Video,
]
if (fileTypeList.includes(message.type())) {
const fileBox = await message.toFileBox()
console.info(`Saving file {$fileBox.name}...`)
await fileBox.toFile()
}
}
bot.on('message', onMessage)

About FileBox#

Learn more about how to use FileBox module by reading its document at https://github.com/huan/file-box

Last updated on by Souvik Biswas