读取联系人信息
获取当前机器人账号全部联系人信息
javascript
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 对象属性
javascript
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
}
联系人接口
存储联系人信息
存储指定联系人头像案例
javascript
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("晚安宝宝")
})
待更新···