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
}

联系人接口

在这里插入图片描述

上一篇:MySQL数据库下载及安装教程(下载安装篇)


下一篇:日期专题:做题笔记 (时间显示/星期计算/星系炸弹/第几天/纪念日)