ContactSelf

Last updated 3 months ago

ContactSelf

这个类继承自 Contact

Kind: global class

contactSelf.avatar([file]) ⇒ Promise.

获取 / 设置 机器人的头像。

Kind: instance method of ContactSelf

Param

Type

[file]

FileBox

Example ( GET the avatar for bot, return {Promise<FileBox>})

// Save avatar to local file like `1-name.jpg`
bot.on('login', (user: ContactSelf) => {
console.log(`user ${user} login`)
const file = await user.avatar()
const name = file.name
await file.toFile(name, true)
console.log(`Save bot avatar: ${contact.name()} with avatar file: ${name}`)
})

Example (SET the avatar for a bot)

import { FileBox } from 'file-box'
bot.on('login', (user: ContactSelf) => {
console.log(`user ${user} login`)
const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
await user.avatar(fileBox)
console.log(`Change bot avatar successfully!`)
})

contactSelf.qrcode() ⇒ Promise.

获取机器人的二维码。

Kind: instance method of ContactSelf Example

import { generate } from 'qrcode-terminal'
bot.on('login', (user: ContactSelf) => {
console.log(`user ${user} login`)
const qrcode = await user.qrcode()
console.log(`Following is the bot qrcode!`)
generate(qrcode, { small: true })
})

contactSelf.signature(signature)

修改机器人签名。

Kind: instance method of ContactSelf

Param

Description

signature

机器人要修改的签名内容

Example

bot.on('login', async user => {
console.log(`user ${user} login`)
try {
await user.signature(`Signature changed by wechaty on ${new Date()}`)
} catch (e) {
console.error('change signature failed', e)
}
})