[feature] send login QR by Email/App/ServerChan/...
Created by: dcsan
when wechaty is deployed remotely, its difficult to get the QR to login with.
this code snippet below will send the QR code by email, making it easier for anyone to login
function handleScan(url, code) {
if(urls[url]) {
console.log(`already notified user for ${url}`)
return
}
urls[url] = true
var config = reload('./config.json')
if(config.email && config.mailgun) {
var mg = reload('./mailgun.js')
if(mg.isValidMailgunConfig(config.mailgun)) {
/* eslint-disable no-sync */
var filename = tmp.tmpNameSync({template: '/tmp/qrcode-XXXXXX.jpg'});
mg.getHttpFile(url, filename, () => mg.email(
mg.createMailgunClient(config.mailgun),
mg.createEmailData(config.mailgun, filename, url))
.then((body) => console.log(body))
.catch((err) => console.log(err)))
} else {
console.log(`invalid configuration ${JSON.stringify(config.mailgun)}`)
}
} else {
console.log('warning: mailgun not configured')
}
console.log(`Scan QR Code to login: ${code}\n${url}`)
}
Wechaty.instance()
.on('scan', handleScan)
also this mailgun file to send the image https://github.com/coderbunker/candobot/blob/master/mailgun.js
source https://github.com/coderbunker/candobot/blob/master/bot.js#L20-L33