mirror of
https://github.com/wechaty/getting-started.git
synced 2026-10-24 18:50:01 +08:00
36 lines
745 B
JavaScript
36 lines
745 B
JavaScript
const { Wechaty } = require('wechaty')
|
|
|
|
function onScan (qrcode, status) {
|
|
require('qrcode-terminal').generate(qrcode, { small: true }) // show qrcode on console
|
|
|
|
const qrcodeImageUrl = [
|
|
'https://api.qrserver.com/v1/create-qr-code/?data=',
|
|
encodeURIComponent(qrcode),
|
|
].join('')
|
|
|
|
console.log(qrcodeImageUrl)
|
|
}
|
|
|
|
function onLogin (user) {
|
|
console.log(`${user} login`)
|
|
}
|
|
|
|
function onLogout(user) {
|
|
console.log(`${user} logout`)
|
|
}
|
|
|
|
async function onMessage (msg) {
|
|
console.log(msg.toString())
|
|
}
|
|
|
|
const bot = new Wechaty()
|
|
|
|
bot.on('scan', onScan)
|
|
bot.on('login', onLogin)
|
|
bot.on('logout', onLogout)
|
|
bot.on('message', onMessage)
|
|
|
|
bot.start()
|
|
.then(() => console.log('Starter Bot Started.'))
|
|
.catch(e => console.error(e))
|