project,

"Praise Robot Based on Wechaty"

yinizhilian yinizhilian Follow Jul 23, 2020 · 2 mins read

Wechaty Badge Everything about Wechaty

    During the epidemic, I remember adding a friend on WeChat. When I sent him a message, he could reply immediately. Later I learned that some of them were replied by robots. I was very curious about how this was done, because I only knew that WeChat official accounts could do it. Can WeChat also do it? Because of curiosity, I searched for relevant information on the Internet and learned about the powerful wechaty. It just so happens that my research direction is natural language processing. The praise robot on the official account was very popular some time ago, so I thought about writing a WeChat version of the praise robot. If you want to experience it, you can add: AINLPER-BOT. The implementation of related functions is not perfect, please don’t spray it~

What is a praise robot?

A praise robot is a chatbot that can praise you. You can send it a message, and it will reply with a praise.

How to build a praise robot?

We can use Wechaty to build a praise robot. We can use the following code to implement this solution:

import { Wechaty } from 'wechaty'

const bot = new Wechaty()

bot.on('scan', (qrcode, status) => {
  console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`)
})

bot.on('login', (user) => {
  console.log(`User ${user} logged in`)
})

bot.on('message', async (message) => {
  if (message.text() === 'ding') {
    await message.say('dong')
  }
})

bot.start()

Conclusion

Wechaty is a powerful tool for building WeChat bots. It can be used to build a praise robot. I believe that in the future, Wechaty will become more and more popular.

Join Newsletter
Get the latest news right in your inbox. We never spam!
Written by yinizhilian
a little coder && we media