Skip to content

Commit

Permalink
#4 example for support save image by message stream
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jun 14, 2016
1 parent 9c44989 commit 7186caa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion example/image-bot.js
Expand Up @@ -7,15 +7,20 @@ bot
})
.on('message', m => {
console.log(`RECV: ${m}`)

if (m.type() === Wechaty.Message.Type.IMAGE) {
console.log('IMAGE url: ' + m.get('url'))
const filename = m.id + '.jpg'
console.log('IMAGE local filename: ' + filename)

var fileStream = require('fs').createWriteStream(filename)

m.readyStream()
.then(stream => stream.pipe(fileStream))
.catch(e => log.error('stream error', e))
.catch(e => console.log('stream error:' + e))

}

})
.init()
.catch(e => console.error('bot.init() error: ' + e))

0 comments on commit 7186caa

Please sign in to comment.