---
description: 自动通过入群邀请
---

# RoomInvitation

## RoomInvitation

自动通过入群邀请

**Kind**: global class

* [RoomInvitation](#roominvitation)
  * [.accept()](#roominvitation-accept-promise) ⇒ `Promise <void>`
  * [.inviter()](#roominvitation-inviter-contact) ⇒ `Promise <Contact>`
  * [.topic()](#roominvitation-topic-contact) ⇒ `Promise <string>`
  * [~~.roomTopic()~~](#roominvitation-roomtopic) ⇒ `Promise <string>`
  * [.date()](#roominvitation-date-promise) ⇒ `Promise <Date>`
  * [.age()](#roominvitation-age-number) ⇒ `Promise <number>`

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

自动通过入群邀请

**Kind**: instance method of [`RoomInvitation`](#roominvitation)\
**Example**

```javascript
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  try {
    console.log(`received room-invite event.`)
    await roomInvitation.accept()
  } catch (e) {
    console.error(e)
  }
}
.start()
```

### roomInvitation.inviter() ⇒ `Promise <Contact>`

获取发送入群邀请的联系人。

**Kind**: instance method of [`RoomInvitation`](#roominvitation)\
**Example**

```javascript
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  const inviter = await roomInvitation.inviter()
  const name = inviter.name()
  console.log(`received room invitation event from ${name}`)
}
.start()
```

### roomInvitation.topic() ⇒ `Promise <string>`

获取需要进的群的群名称.

**Kind**: instance method of [`RoomInvitation`](#roominvitation)\
**Example**

```javascript
const bot = new Wechaty()
bot.on('room-invite', async roomInvitation => {
  const topic = await roomInvitation.topic()
  console.log(`received room invitation event from room ${topic}`)
}
.start()
```

### ~~roomInvitation.roomTopic()~~

**Kind**: instance method of [`RoomInvitation`](#RoomInvitation)\
**Deprecated:**: 请使用 [topic() ](#roominvitation-topic-contact)

### roomInvitation.date() ⇒ `Promise <Date>`

获取发送入群邀请的时间。

**Kind**: instance method of [`RoomInvitation`](#roominvitation)

### roomInvitation.age() ⇒ `Promise <number>`

获取入群邀请的时间间隔。

例如：入群邀请的发送时间在 `8:43:01`, 当我们在Wechaty 上收到这个信息的时间是 `8:43:15`, 那么 age() 的值为： `8:43:15 - 8:43:01 = 14 (seconds)`

**Kind**: instance method of [`RoomInvitation`](#roominvitation)
