How to use the wechaty.Message.Type function in wechaty

To help you get started, we’ve selected a few wechaty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wechaty / wechaty-getting-started / examples / professional / speech-to-text-bot.ts View on Github external
.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 {
github wechaty / wechaty-getting-started / examples / tuling123-bot.js View on Github external
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)
  }
}
github kaiyuanshe / oss-bot / src / handlers / on-message.ts View on Github external
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')
    }
  }

}
github Papeone / wechatrobot / src / on-message.js View on Github external
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)
    }

}
github wechaty / wechaty-getting-started / examples / advanced / media-file-bot.js View on Github external
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)
  }
}