You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I clone the "wechaty-getting-started", and modify the init code of Wechaty in "examples/starter-bot.js". Then in the console, I run "npm install" and "npm start". However, after I scan the qrcode, I got nothing in the console. After a while, I got status -106. And I found issue #176, and it mentions "puppet-padchat-patch" can solve the -106 issue. "puppet-padchat-patch" can show me a new qrcode, but I cannot login after I scan the new qrcode.
My codes as below.
const { Wechaty } = require('wechaty')
const { PadchatPatch } = require('puppet-padchat-patch')
const TOKEN = 'myToken'; // the token I applied
const initialName = 'test';
const puppet = 'wechaty-puppet-padchat'
const puppetOptions = {
token: TOKEN
}
const bot = new Wechaty({
initialName,
puppet,
puppetOptions,
});
bot.on('scan', onScan)
bot.on('login', onLogin)
bot.on('logout', onLogout)
bot.on('message', onMessage)
bot.start()
.then(() => console.log('Starter Bot Started.'))
.catch(e => console.error(e))
function onScan (qrcode, status) {
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
].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())
}
/**
* Hook the -106 failure status here, try to get auth data from separate server
*/
process.on('unhandledRejection', (error) => {
const { message } = error
if (message && message.indexOf('unknown status: -106') !== -1) {
const wxid = message.split(' ').slice(-1)[0]
const padchatPatch = new PadchatPatch(TOKEN, initialName, wxid)
padchatPatch
.on('scan', (qrcode, status) => {
// You need to let the user scan the qrcode again here
// generate(qrcode, { small: true })
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
].join('')
console.log(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `)
})
.on('finish', async () => {
// restart your application here
bot.start()
})
.start()
return
}
})
The text was updated successfully, but these errors were encountered:
I clone the "wechaty-getting-started", and modify the init code of Wechaty in "examples/starter-bot.js". Then in the console, I run "npm install" and "npm start". However, after I scan the qrcode, I got nothing in the console. After a while, I got status -106. And I found issue #176, and it mentions "puppet-padchat-patch" can solve the -106 issue. "puppet-padchat-patch" can show me a new qrcode, but I cannot login after I scan the new qrcode.
My codes as below.
The text was updated successfully, but these errors were encountered: