# 方法

## setImToken(token: string)

> 更新实例token

```javascript
myIm.setImToken('new token')
```

## setImApiKey(apiKey: string)

> 更新实例ApiKey

```javascript
myIm.setImApiKey('new apiKey')
```

## getUserInfo(address?: string)

> 获取用户基础信息

| **参数**  | **类型** | **描述**                                          | **默认** |
| ------- | ------ | ----------------------------------------------- | ------ |
| address | string | 可选，用户的`relationId`或者web3地址, address 为空时表示获取自身信息 |        |

## getFollowing(data: { address: string, cursor?: string, limit?: number })

> 获取关注的人列表

| **参数**  | **类型** | **描述**                                | **默认** |
| ------- | ------ | ------------------------------------- | ------ |
| address | string | 必选，用户的`relationId`或者web3地址            |        |
| cursor  | string | 可选，上一页返回的 cursor 数据, cursor 为空表示查询第一页 |        |
| limit   | number | 可选，每页返回数量，上限100                       | 20     |

## recommend(data: { address: string, cursor?: string, limit?: number })

> 推荐引擎根据用户twitter关注、以太坊链上交易、持有的nft、当前following的用户进行好友推荐

| **参数** | **类型** | **描述**                                | **默认** |
| ------ | ------ | ------------------------------------- | ------ |
| cursor | string | 可选，上一页返回的 cursor 数据, cursor 为空表示查询第一页 |        |
| limit  | number | 可选，每页返回数量，上限100                       | 20     |

## follow(address: string)

> 关注一个用户

| **参数**  | **类型** | **描述**                       | **默认** |
| ------- | ------ | ---------------------------- | ------ |
| address | string | 必选，对方用户的`relationId`或者web3地址 |        |

## unfollow(address: string)

> 取关一个用户

| **参数**  | **类型** | **描述**                       | **默认** |
| ------- | ------ | ---------------------------- | ------ |
| address | string | 必选，对方用户的`relationId`或者web3地址 |        |

## sendMessage(data: sendMessageType)

> 发送消息（sendMessageType参数如下）

| **参数**                                                                                                                | **类型** | **描述**             | **默认**    |
| --------------------------------------------------------------------------------------------------------------------- | ------ | ------------------ | --------- |
| content                                                                                                               | string | 消息内容               | 必选，消息文本内容 |
| channelUuid                                                                                                           | string | 可选，会话uuid          | -         |
| toRelationId                                                                                                          | string | 可选，对方的`relationId` | -         |
| sendUuid                                                                                                              | string | 可选，消息uuid          |           |
| type                                                                                                                  | string | 可选，消息类型            | TEXT      |
| 说明：`channelUuid`与`toRelationId`不能同时为空，`sendUuid`为空时方法内部将根据`channelUuid`与`toRelationId`以当前时间戳和随机数拼接成字符串当作默认的`sendUuid` |        |                    |           |
| 如果是给从未对话过的用户发送消息，发送成功后将自动新创建聊天会话，返回`channelUuid`                                                                      |        |                    |           |

## userChannelsList(data: listRequestType)

> 获取用户会话列表（listRequestType参数如下）

| **参数**  | **类型** | **描述**                             | **默认**      |
| ------- | ------ | ---------------------------------- | ----------- |
| keyword | string | 可选，降序                              | 会话名称，支持模糊查询 |
| cursor  | string | 可选，上一页返回的 cursor数据，cursor为空表示查询第一页 |             |
| limit   | number | 可选，每页返回数量                          | 20          |

## messageList(data: messageListRequestType)

> 获取用户会话内的消息列表（messageListRequestType参数如下）

| **参数**       | **类型** | **描述**                             | **默认** |
| ------------ | ------ | ---------------------------------- | ------ |
| maxCreateAt  | number | 必选，时间戳，毫秒为单位。需要大于或等于当前页最后一条消息的发送时间 | -      |
| channelUuid  | string | 可选，会话uuid                          | -      |
| toRelationId | string | 可选，对方的`toRelationId`               | -      |
| limit        | number | 可选，每页返回数量                          | 50     |

## channelCreate(data: {members, name, type})

> 创建新会话

| **参数**  | **类型**    | **描述**                                                  | **默认** |
| ------- | --------- | ------------------------------------------------------- | ------ |
| name    | string    | 必选，群名称                                                  |        |
| type    | string    | 必选，群类型，当前枚举值： G-普通群组，P-p2p聊天群组                          |        |
| members | string\[] | 群成员的relationId集合。如果type=P，则只会将调用者和首个用户作为群聊成员。群管理员为当前调用者 | -      |

## channelInfo(channelUuid: string)

> 获取会话详情

| **参数**      | **类型** | **描述**    | **默认** |
| ----------- | ------ | --------- | ------ |
| channelUuid | string | 必选，会话uuid | -      |

## channelDisband(channelUuid: string)

> 解散会话

| **参数**      | **类型** | **描述**    | **默认** |
| ----------- | ------ | --------- | ------ |
| channelUuid | string | 必选，会话uuid | -      |

## channelMemberLeave(channelUuid: string)

> 当前用户退出会话

| **参数**      | **类型** | **描述**    | **默认** |
| ----------- | ------ | --------- | ------ |
| channelUuid | string | 必选，会话uuid | -      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://relationlabs.gitbook.io/relation-one-api/api-zh/js-sdk/im-js-sdk/method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
