wechaty / python-wechaty-puppet

Python Puppet Provider Abstraction for Wechaty
https://pypi.org/project/wechaty-puppet/
Apache License 2.0
12 stars 11 forks source link

improve from_file method #26

Closed wj-Mcat closed 4 years ago

wj-Mcat commented 4 years ago

When I improve this method, I find that the type of base64 data field is bytes, not str. So I fix this data typing bugs.

And more, @huan I test the fromFile method in ts-wechaty with wechaty-puppet-hostie to send local file, it also throw the unsupported protocol file-box-type error.

async function onMessage (msg: Message) {
  log.info('StarterBot', msg.toString())

  if (msg.text() === 'ding') {
    const file = FileBox.fromFile('./README.md')
    await msg.say(file)
  }
}

So, to make from_file work well now, I change the protocol FileBoxType in from_file method to Base64 Type. And it can work well.

huan commented 4 years ago

And more, @huan I test the fromFile method in ts-wechaty with wechaty-puppet-hostie to send local file, it also throw the unsupported protocol file-box-type error.

Yes, that's we are using the GRPC and the FileBox has to be serialized via the JSON.stringify().

I believe we can rely on your current solution for working around this:

  1. user uses FileBox.fromFile() to load a file
  2. FileBox load the local file and set itself a base64 type
  3. Then it will be ok to use with hostie/GRPC.

Additionally, if you want to align with TS more strictly, please see the issue that talking about the FileBox types with the GRPC serialization: https://github.com/huan/file-box/issues/25