Bot itself will be encapsulated as a ContactSelf.
Tips: this class is extends Contact
Kind: global class
GET / SET bot avatar
Kind: instance method of ContactSelf
Param | Type |
[file] |
|
Example ( GET the avatar for bot, return {Promise<FileBox>})
// Save avatar to local file like `1-name.jpg`bot.on('login', async user => {console.log(`user ${user} login`)const file = await user.avatar()const name = file.nameawait file.toFile(name, true)console.log(`Save bot avatar: ${user.name()} with avatar file: ${name}`)})
Example (SET the avatar for a bot)
import { FileBox } from 'file-box'bot.on('login', user => {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!`)})
Get bot qrcode
Kind: instance method of ContactSelf
Example
import { generate } from 'qrcode-terminal'bot.on('login', async user => {console.log(`user ${user} login`)const qrcode = await user.qrcode()console.log(`Following is the bot qrcode!`)generate(qrcode, { small: true })})
Change bot signature
Kind: instance method of ContactSelf
Param | Description |
signature | The new signature that the bot will change to |
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)}})
Get or change bot name.
Kind: instance method of ContactSelf
Param | Description |
[name] | The new alias that the bot will change to |
Example
bot.on('login', async user => {console.log(`user ${user} login`)const oldName = user.name() // get bot nametry {await user.name(`${oldName}-${new Date().getTime()}`) // change bot name} catch (e) {console.error('change name failed', e)}})