-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
39 lines (36 loc) · 1.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { ScanStatus, WechatyBuilder } from 'wechaty'
import QrcodeTerminal from 'qrcode-terminal'
const token = 'puppet_workpro_example_token' // put your token here
const bot = WechatyBuilder.build({
puppet: 'wechaty-puppet-service',
puppetOptions: {
token,
tls: {
disable: true
// currently we are not using TLS since most puppet-service versions does not support it. See: https://github.com/wechaty/puppet-service/issues/160
}
}
})
bot.on('scan', (qrcode, status, data) => {
console.log(`
============================================================
qrcode : ${qrcode}, status: ${status}, data: ${data}
============================================================
`)
if (status === ScanStatus.Waiting) {
QrcodeTerminal.generate(qrcode, {
small: true
})
}
}).on('login', user => {
console.log(`
============================================
user: ${JSON.stringify(user)}, friend: ${user.friend()}, ${user.coworker()}
============================================
`)
}).on('message', message => {
console.log(`new message received: ${JSON.stringify(message)}`)
}).on('error', err => {
console.log(err)
})
bot.start()