Closed System233 closed 2 years ago
import { FileBox } from "file-box"; import {WechatyBuilder,Message} from "wechaty" import {generate} from "qrcode-terminal" const bot=WechatyBuilder.build({puppet:'wechaty-puppet-wechat',name:'db'}); bot.on('scan',code=>generate(code,{small:true})) .on('message',async(msg:Message)=>{ const target=msg.room()||msg.listener(); if(target){ if(msg.type()==bot.Message.Type.Text){ const text=msg.text(); if(/pdf/i.test(text)){ console.log(`正在发送PDF`); const file=FileBox.fromFile("test.pdf"); await target.say(file) console.log(`PDF发送完成`); }else if(/image/.test(text)){ console.log(`正在发送图片`); const file=FileBox.fromFile("test.png"); await target.say(file); console.log(`图片发送完成`); } }else if(msg.type()==bot.Message.Type.Image){ const file=await msg.toFileBox(); console.log(`收到图片:${file.name}`) const path="received-"+file.name; await file.toFile(path); console.log(`保存图片:${path}`) } } }); bot.start();
0.npm install wechaty wechaty-puppet-wechat file-box qrcode-terminal
npm install wechaty wechaty-puppet-wechat file-box qrcode-terminal
test.pdf
pdf
I'm not sure whether the .PDF file type is sealed correctly.
.PDF
Please refer to the below code to see if you can figure something out:
https://github.com/wechaty/puppet-wechat/blob/c93ce9366671aee264716ac151ebea5ed037ad2a/src/puppet-wechat.ts#L1245-L1258
Steps to reproduce
0.
npm install wechaty wechaty-puppet-wechat file-box qrcode-terminal
test.pdf
in current directorypdf
from WeChat client to anywhere.