前期准备工作

token的获取

pad-local

手机号获取

Potato

记录

  1. 初始化Wechaty时可以传递name属性以生成{name}.memory-card.json
    // bot.ts
    

import { Contact, Message, Wechaty } from 'wechaty'
import { ScanStatus } from 'wechaty-puppet'
import { PuppetPadplus } from 'wechaty-puppet-padplus'
import QrcodeTerminal from 'qrcode-terminal'

const token = 'your-token'

const puppet = new PuppetPadplus({
token,
})

const name = 'your-bot-name'

const bot = new Wechaty({
puppet,
name, // generate xxxx.memory-card.json and save login data for the next login
})

bot
.on('scan', (qrcode, status) => {
if (status === ScanStatus.Waiting) {
QrcodeTerminal.generate(qrcode, {
small: true
})
}
})
.on('login', (user: Contact) => {
console.log(login success, user: ${user})
})
.on('message', (msg: Message) => {
console.log(msg : ${msg})
})
.on('logout', (user: Contact, reason: string) => {
console.log(logout user: ${user}, reason : ${reason})
})
.start()