提交 35330746 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 ec41c449
......@@ -27,6 +27,8 @@ Wechaty is a Bot Framework for Wechat **Personal** Account which can help you cr
> @naishstar: thanks for great SDK [link](https://github.com/wechaty/wechaty/issues/57)
> @lijiarui: [Chat实录|李佳芮:向前一步的程序媛](http://mp.weixin.qq.com/s/dWHAj8XtiKG-1fIS5Og79g)
# Example
The shortest wechat bot code in the world: 6 lines JavaScript
......
......@@ -35,26 +35,25 @@ bot
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
})
.on('login' , user => console.log(`${user} logined`))
.on('message', async function(this, m) {
console.log(`RECV: ${m}`)
.on('message', async function(this, msg) {
console.log(`RECV: ${msg}`)
if (m.type() !== MsgType.VOICE) {
if (msg.type() !== MsgType.VOICE) {
return // skip no-VOICE message
}
const mp3File = createWriteStream(m.filename())
const mp3Stream = await (msg as MediaMessage).readyStream()
const mp3Stream = await (m as MediaMessage).readyStream()
mp3Stream.pipe(mp3File)
const file = createWriteStream(msg.filename())
mp3Stream.pipe(file)
const text = await speechToText(mp3Stream)
console.log('VOICE TO TEXT: ' + text)
if (m.self()) {
if (msg.self()) {
this.say(text) // send text to 'filehelper'
} else {
m.say(text) // to original sender
msg.say(text) // to original sender
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册