Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add API docs Chinese version #1530

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: ContactSelf
---

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

## ContactSelf

> 备注:这个类继承自 Contact

**Kind**: global class

* ContactSelf
* 实例
* contactSelf.avatar\(\[file\]\) ⇒ `Promise <void | FileBox>`
* contactSelf.qrcode\(\) ⇒ `Promise <string>`
* contactSelf.signature\(signature\) ⇒ `Promise <string>`
* contactSelf.name\(\[name\]\) ⇒ `Promise <void> | string`
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for instance methods (avatar, qrcode, signature, name) is well-structured, providing method signatures and return types. This structure aids in quick comprehension of what each method does. However, ensure consistency in the documentation style for return types. For example, Promise <void | FileBox> and Promise<void> | string have slightly different spacing around the | symbol. Consistency in such details improves readability.

- * contactSelf.avatar\(\[file\]\) ⇒ `Promise <void | FileBox>`
+ * contactSelf.avatar\(\[file\]\) ⇒ `Promise<void | FileBox>`
- * contactSelf.name\(\[name\]\) ⇒ `Promise <void> | string`
+ * contactSelf.name\(\[name\]\) ⇒ `Promise<void> | string`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* contactSelf.avatar\(\[file\]\) ⇒ `Promise <void | FileBox>`
* contactSelf.qrcode\(\) ⇒ `Promise <string>`
* contactSelf.signature\(signature\) ⇒ `Promise <string>`
* contactSelf.name\(\[name\]\) ⇒ `Promise <void> | string`
* contactSelf.avatar\(\[file\]\) ⇒ `Promise<void | FileBox>`
* contactSelf.qrcode\(\) ⇒ `Promise <string>`
* contactSelf.signature\(signature\) ⇒ `Promise <string>`
* contactSelf.name\(\[name\]\) ⇒ `Promise<void> | string`


### contactSelf.avatar\(\[file\]\) ⇒ `Promise <void | FileBox>`

设置机器人的头像

**Kind**: `ContactSelf`的实例方法

| Param | Type |
| :--- | :--- |
| \[file\] | `FileBox` |

**示例** _\( GET the avatar for bot, return {Promise&lt;FileBox&gt;}\)_

```javascript
bot.on('login', async user => {
console.log(`user ${user} login`)
const file = await user.avatar()
const name = file.name
await file.toFile(name, true)
console.log(`Save bot avatar: ${user.name()} with avatar file: ${name}`)
})

### contactSelf.qrcode\(\) ⇒ `Promise <string>`

获取机器人的二维码。

**Kind**: `ContactSelf`的实例方法

#### 示例

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

### contactSelf.signature\(signature\) ⇒ `Promise <void>`

修改机器人签名。

**Kind**: `ContactSelf`的实例方法

| Param | Description |
| :--- | :--- |
| signature | 机器人要修改的签名内容 |

#### 示例

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

### contactSelf.name\(\[name\]\) ⇒ `Promise<void> | string`

修改机器人昵称。

**Kind**: `ContactSelf`的实例方法

| Param | Description |
| :--- | :--- |
| \[name\] | 机器人要修改的昵称内容 |

#### 示例

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