提交 e34248ab 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

example: ding dong auto-replyer

上级 b0c84ccb
const Wechaty = require('../wechaty')
const log = require('npmlog')
//log.level = 'verbose'
const welcome = `
| __ __ _ _
| \\ \\ / /__ ___| |__ __ _| |_ _ _
| \\ \\ /\\ / / _ \\/ __| '_ \\ / _\` | __| | | |
| \\ V V / __/ (__| | | | (_| | |_| |_| |
| \\_/\\_/ \\___|\\___|_| |_|\\__,_|\\__|\\__, |
| |___/
=============== Powered by Wechaty ===============
-------- https://github.com/zixia/wechaty --------
I'm a bot, my super power is talk in Wechat.
If you send me a 'ding', I will reply you a 'dong'!
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me for more super powers!
Please wait... I'm trying to login in...
`
console.log(welcome)
const bot = new Wechaty()
bot.init()
.then(login)
bot.on('message', (m) => {
log.info('Bot', 'recv message: %s', m)
if (/^ding$/.test(m.get('content'))) {
const r = new Wechaty.Message()
r.set('to', m.get('from'))
r.set('content', 'dong')
bot.send(r)
.then(() => { log.info('Bot', 'auto replied') })
}
})
function login() {
log.info('Bot', 'Welcome to Wechaty')
bot.puppet
.getLoginQrImgUrl()
.then(url =>
console.log(`\n\nAction needed. Scan the belowing QRCode to login:\n\n${url}\n\nTip: You can copy/paste it to a web browser.\n`)
).catch(e => log.error('Bot', 'promise rejected'))
}
bot.on('login' , () => npm.info('Bot', 'logined'))
bot.on('logout' , () => npm.info('Bot', 'logouted'))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册