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

发送图片 Demo please #129

Closed
suntong opened this issue Jun 29, 2020 · 3 comments
Closed

发送图片 Demo please #129

suntong opened this issue Jun 29, 2020 · 3 comments
Labels

Comments

@suntong
Copy link
Contributor

suntong commented Jun 29, 2020

Is your feature request related to a problem? Please describe.
How to send an image from a file on disk to people/chart-room via wechaty?

I had the following in my code, which had been working fine before,

 const fileBox = FileBox.fromFile(myFileName)
 await msg.say(fileBox)

but it ceased working since I don't know when.
Maybe after I switched to wechaty-puppet-padplus?

Describe the solution you'd like
A simple demo would be appreciated.
Maybe just add another case to reply with an image in the ding-dong-bot.js or media-file-bot.js file, thanks.

[enhancement]

@huan
Copy link
Member

huan commented Jun 29, 2020

If the above code does not work, then I believe it's a bug.

We have an example in Wechaty repo:

https://github.com/wechaty/wechaty/blob/70edb1d695c3a03e3b10edbb355f7acc753a8138/examples/ding-dong-bot.ts#L144-L150

@huan huan added the question label Jun 29, 2020
@suntong
Copy link
Contributor Author

suntong commented Jun 29, 2020

Oh, thanks for your reply.

Found the problem is my added await msg.say(JSON.stringify(fileBox)), which gave me:

(node:57222) UnhandledPromiseRejectionWarning: Error: FileBox.toJSON() can only work on limited FileBoxType(s). See: <https://github.com/huan/file-box/issues/25>
    at FileBox.toJSON (/.../nodejs/node_modules/file-box/dist/src/file-box.js:303:23)
    at JSON.stringify (<anonymous>)

It's just a plain .png file. Removing that line and things are working again.
thx again!

@suntong suntong closed this as completed Jun 29, 2020
@huan
Copy link
Member

huan commented Jun 29, 2020

Glad to know you have fix it!

The rejection is because the read file is a async operation which can not be satisfied by the tojson call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants