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

fix: update friendship related methods #1510

Merged
merged 2 commits into from
Jan 7, 2023
Merged
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
51 changes: 47 additions & 4 deletions docusaurus/docs/api/friendship.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,63 @@ bot.on('friendship', async friendship => {
.start()
```

### Friendship.add\(contact, hello\) ⇒ `Promise <void>`
### Friendship.search\(phone\) ⇒ `Promise <Contact>`

The method search contact by phone number and get a `contact`. The best practice is to send friend request once per minute. Remember not to do this too frequently, or your account may be blocked.

| Param | Type | Description |
| :--- | :--- | :--- |
| phone | `number` | search phone number |

#### Example

```javascript
const phone = '131xxx1234'
const searchContact = await bot.Friendship.search({
phone,
})
```

### Friendship.add\(contact, options\) ⇒ `Promise <void>`

The method sends a Friend Request to a `contact` with message `hello`.The best practice is to send friend request once per minute. Remember not to do this too frequently, or your account may be blocked.

| Param | Type | Description |
| :--- | :--- | :--- |
| contact | `Contact` | Send friend request to contact |
| hello | `string` | The friend request content |
| options | `FriendshipAddOptions` | The friend request option |

#### Example
#### Example \(add searched contact\)

```javascript
await bot.Friendship.add(searchContact, { hello: 'Nice to meet you! I am wechaty bot!' })
```

#### Example \(add room member\)

```javascript
const memberList = await room.memberList()
for (let i = 0; i < memberList.length; i++) {
await bot.Friendship.add(member, 'Nice to meet you! I am wechaty bot!')
await bot.Friendship.add(member, {
room: message.room(),
hello: 'Nice to meet you! I am wechaty bot!',
})
}

```

#### Example \(add contact card\)

```javascript
if (message.type() === bot.Message.Type.Contact) {
const contact = await message.toContact()
const options = {
contact: message.talker(),
hello: 'Nice to meet you! I am wechaty bot!',
}
if (message.room()) {
options.room = message.room()
}
await bot.Friendship.add(contact, options)
}
```