快速开始
环境安装
开始本教程之前,您的计算机上必须安装Node.js。
申请 ApiKey
可使用下面的 ApiKey 进行体验:581c6c4fa0b54912b00088aa563342a4。 如有生产需要,请填写表格:Relation API Access Request。
通过下面 demo 介绍如何接入 Relation One。
Demo
Repository: https://github.com/relationlabs/relation-im-demo
在线 Demo: https://app.relationlabs.ai/demo/im/
视频引导:
运行 demo:
git clone https://github.com/relationlabs/relation-im-demo.git
cd relation-im-demo
npm install
npm run dev
功能介绍
获取addressAuthToken
import { authByMetamask } from '@relationlabs/auth';
const { authResult } = await authByMetamask();
获取unifiedAuthToken
const { token, error } = await RelationIM.getRelationToken(
authResult.token,
APIKEY
)
获取个人信息
const userInfoRes = await im.getUserInfo()
已关注用户的列表
const res = await im.getFollowing({
address: relationId,
limit,
cursor
})
follow/unfollow
const res = await im.follow(relationId)
const res = await im.unfollow(relationId)
初始化 IM 实例
const im = RelationIM.init({ token, apiKey: APIKEY, connect: true })
会话列表
const res = await im.userChannelsList({
cursor,
limit
})
接收消息
im.bind(Im.RECEIVE_MSG_OK,(event) => {...})
单个会话的消息列表
const res = await im.messageList({
channelUuid,
maxCreateAt: new Date().getTime(),
limit
})
发送消息
const res = await im.sendMessage({
channelUuid,
content
})
深入了解
更多Api请参考:
介绍Last updated