The original link

code

  • Weike-ncov, welcome Star

In addition, this is my early development of the epidemic map of domestic provinces and cities: github.com/shfshanyue/…

Technology stack

  • wechaty
  • wechaty-puppet-padplus

Wechaty is a Bot SDK for Wechat Individual Account which can help you create a bot in 6 lines of javascript, with cross-platform support including Linux, Windows, MacOS, and Docker.

If you need to obtain tokens, please refer here

The effect

test

Please add robot [Shayue-bot], note [epidemic], through friends.

  • Reply to [epidemic] will automatically reply to the epidemic information of the most affected countries.
  • Replies to [Italy] or other countries will automatically return information about the outbreak in that country.

Receiving user messages

The received user information is Message class, and the robot replies according to the received Message.

const { Message } = require('wechaty')
const covid = require('.. /message/covid')

// The keyword corresponds to the handler
const routes = [
  { keyword: 'outbreak'.handle: covid.ncov },
  { keyword: ' '.handle: covid.keyword }
]

async function reply (msg, data) {
  for (const text of data) {
    await msg.say(text)
  }
}

async function handleMessage (msg) {
  // If a text is received
  if (msg.type() == Message.Type.Text) {
    // If not in the group
    if(! msg.room()) {console.log(msg)
      // Find the corresponding handler for this keyword
      const route = routes.find(route= > msg.text().includes(route.keyword))
      // The handler returns the corresponding message reply
      const data = route.handle(msg.text())
      // Reply the message according to the message
      await reply(msg, data)
    }
  }
}

exports.handleMessage = handleMessage
Copy the code

Next step

  • Automatically pass friends
  • Automatic group
  • Daily group broadcast (business information, operation data, monitoring alarm, stock information, fund information)