自学内容网 自学内容网

2024 年最新使用 Wechaty 开源框架搭建部署微信机器人(微信群智能客服案例)

读取联系人信息

获取当前机器人账号全部联系人信息

bot.on('ready', async () => {
    console.log("机器人准备完毕!!!")
    let contactList = await bot.Contact.findAll()
    for (let index = 0; index < contactList.length; index++) {
        const contact = contactList[index];
        if (contact.payload.name == '番茄土豆') {
            console.log(contact)
        }
    }
})

Contact 对象属性

WechatifiedContactImpl {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
id: '@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862',
payload: {
address: '',
alias: '',
avatar: '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=768678887&username=@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862&skey=@crypt_13d84e54_3b3f2c2d3fa4b54729339f73cdf121e6',
city: '',
friend: true,
gender: 0,
id: '@9c7f307a0233472ab92c0d3c8624fd0a2a8522a9d085f0b89a540d23ff76d862',
name: '番茄土豆',
phone: [],
province: '',
signature: '',
star: false,
weixin: '',
type: 1
},
[Symbol(kCapture)]: false
}

联系人接口

在这里插入图片描述

存储联系人信息

存储指定联系人头像案例

bot.on('ready', async () => {
    console.log("机器人开始运行!!!")
    const contact = await bot.Contact.find({ name: "番茄土豆" });
    console.log(contact)

    fileBox = await contact.avatar()
    const filePath = './output.jpg';
    fs.writeFile(filePath, fileBox.buffer, 'binary', (err) => {
        if (err) {
            console.error(err);
        } else {
            console.log("save success!!!");
        }
    });
    await contact.say("晚安宝宝")
})

待更新···


原文地址:https://blog.csdn.net/qq_47452807/article/details/137387086

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!