Wechaty
NewsBlogDevelopersDocs
中文版
中文版
  • 介绍
  • 快速开始
  • API 文档
    • Wechaty
    • Message
    • Contact
    • ContactSelf
    • Room
    • RoomInvitation
    • Friendship
  • 示例代码
  • Puppet
  • 常见问题
  • 最佳实践
  • 参与贡献
  • 了解更多
    • 视频教程
    • 进阶
    • 测试
    • 目录结构
    • ReleaseLog
    • ChangeLog
    • Awesome Wechaty
    • Contributors
    • 关于token的所有问题
Powered by GitBook
On this page
  • ContactSelf
  • contactSelf.avatar() ⇒ Promise
  • contactSelf.avatar(file) ⇒ Promise<void>
  • contactSelf.qrcode() ⇒ Promise<string>
  • contactSelf.name() ⇒ string
  • contactSelf.name(name) ⇒ Promise<string>
  • contactSelf.signature(signature): Promise<void>

Was this helpful?

  1. API 文档

ContactSelf

机器人自己的信息将会封装一个ContactSelf 类. 这个类继承自 Contact

PreviousContactNextRoom

Last updated 5 years ago

Was this helpful?

ContactSelf

这个类继承自 Contact

Kind: global class

Kind: instance method of

contactSelf.avatar() ⇒ Promise

获取机器人的头像

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}`)
})

contactSelf.avatar(file) ⇒ Promise<void>

设置 机器人的头像

Param

Type

file

FileBox

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<string>

获取机器人的二维码。

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.name() ⇒ string

获取 机器人昵称。

Example

bot.on('login', async user => {
  console.log(`user ${user} login`)
  console.log(`user name: ${user.name()}`)
})

contactSelf.name(name) ⇒ Promise<string>

修改机器人昵称。

Param

Description

name

机器人要修改的昵称内容

Example

bot.on('login', async user => {
  console.log(`user ${user} login`)
  const oldName = user.name()
  try {
    await user.name(`${oldName}-${new Date().getTime()}`)
  } catch (e) {
    console.error('change name failed', e)
  }
})

contactSelf.signature(signature): Promise<void>

修改机器人签名。

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)
  }
})

Kind: instance method of Example

Kind: instance method of

Kind: instance method of

Kind: instance method of

ContactSelf
ContactSelf
contactSelf.avatar() ⇒ Promise
contactSelf.avatar(file) ⇒ Promise<void>
contactSelf.qrcode() ⇒ Promise<string>
contactSelf.name() ⇒ string
contactSelf.name(name) ⇒ Promise<string>
contactSelf.signature(signature): Promise<void>
ContactSelf
ContactSelf
ContactSelf
ContactSelf