-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
54 lines (45 loc) · 1.72 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { Wechaty, ScanStatus, log } = require('wechaty');
const handleMessage = require('./event/message');
const schedule = require('./schedule/index');
function onScan(qrcode, status) {
if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
require('qrcode-terminal').generate(qrcode, { small: true }); // show qrcode on console
const qrcodeImageUrl = ['https://wechaty.js.org/qrcode/', encodeURIComponent(qrcode)].join('');
log.info('StarterBot', 'onScan: %s(%s) - %s', ScanStatus[status], status, qrcodeImageUrl);
} else {
log.info('StarterBot', 'onScan: %s(%s)', ScanStatus[status], status);
}
}
function onLogin(user) {
log.info('StarterBot', '%s login', user);
}
function onLogout(user) {
log.info('StarterBot', '%s logout', user);
}
const bot = new Wechaty({
name: 'wechat-bot',
/**
* How to set Wechaty Puppet Provider:
*
* 1. Specify a `puppet` option when instantiating Wechaty. (like `{ puppet: 'wechaty-puppet-padlocal' }`, see below)
* 1. Set the `WECHATY_PUPPET` environment variable to the puppet NPM module name. (like `wechaty-puppet-padlocal`)
*
* You can use the following providers:
* - wechaty-puppet-wechat (no token required)
* - wechaty-puppet-padlocal (token required)
* - wechaty-puppet-service (token required, see: <https://wechaty.js.org/docs/puppet-services>)
* - etc. see: <https://github.com/wechaty/wechaty-puppet/wiki/Directory>
*/
// puppet: 'wechaty-puppet-wechat',
});
bot.on('scan', onScan);
bot.on('login', onLogin);
bot.on('logout', onLogout);
bot.on('message', handleMessage);
bot
.start()
.then(() => {
log.info('StarterBot', 'Starter Bot Started.');
schedule(bot);
})
.catch(e => log.error('StarterBot', e));