> For the complete documentation index, see [llms.txt](https://wechaty.gitbook.io/wechaty/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wechaty.gitbook.io/wechaty/api/friendship.md).

# Friendship

Send, receive friend request, and friend confirmation events.

## Friendship

Send, receive friend request, and friend confirmation events.

1. send request
2. receive request(in friend event)
3. confirmation friendship(friend event)

[Examples/Friend-Bot](https://github.com/Chatie/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts)

**Kind**: global class

* [Friendship](/wechaty/api/friendship.md#Friendship)
  * *instance*
    * [.accept()](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship+accept) ⇒ `Promise <void>`
    * [.hello()](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship+hello) ⇒ `string`
    * [.contact()](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship+contact) ⇒ `Contact`
    * [.type()](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship+type) ⇒ `FriendshipType`
  * *static*
    * [~~.send()~~](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship.send)
    * [.add(contact, hello)](https://wechaty.gitbook.io/wechaty/api/pages/-Lv6cE5Oq2ooJa9HWAqY#Friendship.add) ⇒ `Promise <void>`

### friendship.accept() ⇒ `Promise <void>`

Accept Friend Request

**Kind**: instance method of [`Friendship`](/wechaty/api/friendship.md#Friendship)\
**Example**

```javascript
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    console.log(`received friend event.`)
    switch (friendship.type()) {

    // 1. New Friend Request

    case bot.Friendship.Type.Receive:
      await friendship.accept()
      break

    // 2. Friend Ship Confirmed

    case bot.Friendship.Type.Confirm:
      console.log(`friend ship confirmed`)
      break
    }
  } catch (e) {
    console.error(e)
  }
})
.start()
```

### friendship.hello() ⇒ `string`

Get verify message from

**Kind**: instance method of [`Friendship`](/wechaty/api/friendship.md#Friendship)\
**Example** *(If request content is \`ding\`, then accept the friendship)*

```javascript
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    console.log(`received friend event from ${friendship.contact().name()}`)
    if (friendship.type() === bot.Friendship.Type.Receive && friendship.hello() === 'ding') {
      await friendship.accept()
    }
  } catch (e) {
    console.error(e)
  }
}
.start()
```

### friendship.contact() ⇒ `Contact`

Get the contact from friendship

**Kind**: instance method of [`Friendship`](/wechaty/api/friendship.md#Friendship)\
**Example**

```javascript
const bot = new Wechaty()
bot.on('friendship', friendship => {
  const contact = friendship.contact()
  const name = contact.name()
  console.log(`received friend event from ${name}`)
}
.start()
```

### friendship.type() ⇒ `FriendshipType`

Return the Friendship Type

> Tips: FriendshipType is enum here. \</br>
>
> * FriendshipType.Unknown
> * FriendshipType.Confirm
> * FriendshipType.Receive
> * FriendshipType.Verify

**Kind**: instance method of [`Friendship`](/wechaty/api/friendship.md#Friendship)\
**Example** *(If request content is \`ding\`, then accept the friendship)*

```javascript
const bot = new Wechaty()
bot.on('friendship', async friendship => {
  try {
    if (friendship.type() === bot.Friendship.Type.Receive && friendship.hello() === 'ding') {
      await friendship.accept()
    }
  } catch (e) {
    console.error(e)
  }
}
.start()
```

### ~~Friendship.send()~~

***Deprecated***

use [Friendship#add](/wechaty/api/friendship.md#friendship-add-contact-hello-promise) instead

**Kind**: static method of [`Friendship`](/wechaty/api/friendship.md#Friendship)

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

Send a Friend Request to a `contact` with message `hello`.

The best practice is to send friend request once per minute. Remeber not to do this too frequently, or your account may be blocked.

**Kind**: static method of [`Friendship`](/wechaty/api/friendship.md#Friendship)

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

**Example**

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