mirror of
https://github.com/wechaty/getting-started.git
synced 2026-10-29 14:09:10 +08:00
make it simple
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const qrTerm = require('qrcode-terminal')
|
||||
|
||||
const {
|
||||
Wechaty,
|
||||
Room
|
||||
} = require('wechaty')
|
||||
|
||||
const bot = new Wechaty()
|
||||
|
||||
bot.on('scan', onScan)
|
||||
bot.on('login', onLogin)
|
||||
bot.on('logout', onLogout)
|
||||
bot.on('message', onMessage)
|
||||
|
||||
bot.start()
|
||||
.catch(console.error)
|
||||
|
||||
function onScan (qrcode, status) {
|
||||
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
|
||||
|
||||
const qrcodeImageUrl = [
|
||||
'https://api.qrserver.com/v1/create-qr-code/?data=',
|
||||
encodeURIComponent(qrcode),
|
||||
'&size=220x220&margin=20',
|
||||
].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())
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
const { Wechaty, Room } = require('wechaty')
|
||||
const qrTerm = require('qrcode-terminal')
|
||||
|
||||
const bot = new Wechaty()
|
||||
|
||||
bot.on('scan', (qrcode, status) => {
|
||||
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
|
||||
|
||||
const qrcodeImageUrl = [
|
||||
'https://api.qrserver.com/v1/create-qr-code/?data=',
|
||||
encodeURIComponent(qrcode),
|
||||
'&size=220x220&margin=20',
|
||||
].join('')
|
||||
|
||||
console.log(qrcodeImageUrl)
|
||||
})
|
||||
|
||||
bot.on('login', user => {
|
||||
console.log(`${user} login`)
|
||||
})
|
||||
|
||||
bot.on('message', async function (msg) {
|
||||
console.log(msg.toString())
|
||||
})
|
||||
|
||||
bot.start()
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Wechaty, Room } from 'wechaty'
|
||||
|
||||
const qrTerm = require('qrcode-terminal')
|
||||
|
||||
const bot = new Wechaty()
|
||||
|
||||
bot.on('scan', (qrcode, status) => {
|
||||
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
|
||||
|
||||
const qrcodeImageUrl = [
|
||||
'https://api.qrserver.com/v1/create-qr-code/?data=',
|
||||
encodeURIComponent(qrcode),
|
||||
'&size=220x220&margin=20',
|
||||
].join('')
|
||||
|
||||
console.log(qrcodeImageUrl)
|
||||
})
|
||||
|
||||
bot.on('login', user => {
|
||||
console.log(`${user} login`)
|
||||
})
|
||||
|
||||
bot.on('message', async function (msg) {
|
||||
console.log(msg.toString())
|
||||
})
|
||||
|
||||
bot.start()
|
||||
@@ -1,6 +0,0 @@
|
||||
const { Wechaty } = require('wechaty') // import { Wechaty } from 'wechaty'
|
||||
Wechaty.instance() // Global Instance
|
||||
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\n${qrcode}`))
|
||||
.on('login', user => console.log(`User ${user} logined`))
|
||||
.on('message', message => console.log(`Message: ${message}`))
|
||||
.start()
|
||||
+1
-2
@@ -4,8 +4,7 @@
|
||||
"description": "Wechaty is an easy to use Wechat Chat Bot SDK. This repo contains the code about the video tutorial.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "ts-node examples/simplest-bot/bot.ts",
|
||||
"six-lines-bot": "node examples/six-lines-bot.js",
|
||||
"start": "ts-node examples/basic-bot.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user