本文主要是介绍wechaty微信机器人收到好友请求时自动同意,并回复一条默认消息,且发一封邮件给管理员,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
https://wechaty.js.org/zh/docs/howto/event#friendship-event-friend-requests
//微信登录
const chatWx = async (req, res) => {try {// 扫码const onScan = (qrcode, status) => {let qrcodeImageUrlif (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {// 在控制台显示二维码qrTerminal.generate(qrcode, { small: true })qrcodeImageUrl = ['https://api.qrserver.com/v1/create-qr-code/?data=',encodeURIComponent(qrcode),].join('')console.log('onScan:', qrcodeImageUrl, ScanStatus[status], status)} else {log.info('onScan: %s(%s)', ScanStatus[status], status)}console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`)console.log(qrcode)res.send({code: 200,data: {qrcode1: `https://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`,qrcode,qrcodeImageUrl,},message: '成功',})return}// 登录const onLogin = (user) => {console.log(`${user} has logged in`)const date = new Date()console.log(`Current time:${date}`)console.log(`Automatic robot chat mode has been activated`)}// 登出const onLogout = (user) => {console.log(`${user} has logged out`)customSendEmail({subject: '微信机器人掉线',html: `微信机器人掉线`,})}// 收到好友请求const onFriendShip = async (friendship) => {if (friendship.type() === 2) {await friendship.accept()// if want to send msg , you need to delay sometimesawait new Promise((r) => setTimeout(r, 1000))await friendship.contact().say(
`免费向微信机器人提问的格式:
gpt,xxx
speech,xxx(文本转语音)
付费后向微信机器人提问的格式:
gpt4,xxx
claude3,xxx
mistral,xxx
mj,xxx(AI绘画)
gemini,xxx
文心一言v4,xxx
upload
uploadForMJ
whisper,xxx(xxx为音频或视频链接,语音转文本)
可以加微信机器人私聊
网站:
https://chat.xutongbao.top`)console.log('after accept')let contact = friendship.contact()let alias = (await contact.alias()) || (await contact.name()) // 发消息人昵称customSendEmail({subject: '微信机器人加入新朋友',html: `微信机器人加入新朋友:${alias}`,})}}const onMessage = async (msg) => {await handleMessage({ msg, bot })}let bot// eslint-disable-next-lineif (global.isLocal) {const CHROME_BIN = process.env.CHROME_BIN? { endpoint: process.env.CHROME_BIN }: {}// eslint-disable-next-lineconst puppet = new PuppetPadlocal({token: 'xxx',})bot = WechatyBuilder.build({name: 'WechatEveryDay',puppet: 'wechaty-puppet-wechat4u', // 如果有token,记得更换对应的puppet 免费//puppet, //需要花钱//puppet: 'wechaty-puppet-wechat', // 如果 wechaty-puppet-wechat 存在问题,也可以尝试使用上面的 wechaty-puppet-wechat4u ,记得安装 wechaty-puppet-wechat4upuppetOptions: {uos: true,...CHROME_BIN,},})} else {bot = WechatyBuilder.build()}// 扫码bot.on('scan', onScan)// 登录bot.on('login', onLogin)// 登出bot.on('logout', onLogout)// 收到消息bot.on('message', onMessage)// 添加好友bot.on('friendship', onFriendShip)// 启动微信机器人bot.start().then(() => console.log('Start to log in wechat...')).catch((e) => console.error(e))} catch (error) {console.log(error)}
}
邮件通知
人工智能学习网站
https://chat.xutongbao.top
这篇关于wechaty微信机器人收到好友请求时自动同意,并回复一条默认消息,且发一封邮件给管理员的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!