Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.on('message', async function(msg) {
console.log(`RECV: ${msg}`)
if (msg.type() !== Message.Type.Audio) {
return // skip no-VOICE message
}
// const mp3Stream = await msg.readyStream()
const msgFile = await msg.file()
const filename = msgFile.name
msgFile.toFile(filename)
const mp3Stream = createReadStream(filename)
const text = await speechToText(mp3Stream)
console.log('VOICE TO TEXT: ' + text)
if (msg.self()) {
await this.say(text) // send text to 'filehelper'
} else {
async function onMessage (msg) {
// Skip message from self, or inside a room
if (msg.self() || msg.room() || msg.from().name() === '微信团队' || msg.type() !== Message.Type.Text) return
console.log('Bot', 'talk: %s' , msg.text())
try {
const {text: reply} = await tuling.ask(msg.text(), {userid: msg.from()})
console.log('Tuling123', 'Talker reply:"%s" for "%s" ',
reply,
msg.text(),
)
await msg.say(reply)
} catch (e) {
console.error('Bot', 'on message tuling.ask() exception: %s' , e && e.message || e)
}
}
const type = message.type()
const room = message.room()
// const from = message.from()
const mentionSelf = await message.mentionSelf()
if (room) {
if (!mentionSelf) {
return
}
log.info('on-message', 'dingDong() message in room and mentioned self')
text = await message.mentionText()
console.info('mentionText', text)
}
if (type === Message.Type.Text) {
if (text.match(/^#ding$/i)) {
await message.say('dong')
}
}
}
async function onMessage(userKey, msg) {
console.log(` ${userKey} Message: ${msg}`);
// Skip message from self, or inside a room
if (msg.self() || msg.room() || msg.from().name() === '微信团队' || msg.text() === 'Ai小哆' || msg.type() !== Message.Type.Text) {
return;
}
let text = msg.text();
console.log("msg text " + text);
try {
const {text: reply, url: url} = await tuling.ask(msg.text(), {userid: msg.from()});
await msg.say(reply);
await msg.say(url)
} catch (e) {
console.error('Bot', 'on message tuling.ask() exception: %s', e && e.message || e)
}
}
async function onMessage(msg) {
console.log(`RECV: ${msg}`)
if (msg.type() !== Message.Type.Text) {
const file = await msg.file()
const name = file.name
console.log('Save file to: ' + name)
file.toFile(name)
}
}