Tips
- 创建会话 -> chatId
- sendMessage -> chatId or userUUID
- 区分私有和群组
- emoji?
endpoint
post /chats/messages
发送消息
tips
- 已知 chatId
- 无 chatId
- 新建 chat
- 传 userId 私聊
- 传 userIds 建立讨论组 ??? next
- 传 groupId 向已有 group 里发消息
- 新建 chat
req
- header
{
token:'xxxxxxx'
}
- body
{
chatId:'xxxxxxxxxxxx',
userUUID:'xxxxxxxxxxxxxxxxx', //without chatId -> createGroup/createChat??
userUUIDs:'xxxxxxxxxxxx',
groupUUID:'xxxxxxxxxxxxxxxxx', //without
message:{
type:'text', //text\docId\link\location\profileId
content:'xxxxxxxxx'
}
}
res
{
id:'xxxxxxx',
chatId:'xxxxxxxxxxxx',
// groupId:'xxxxx',
code:200,
}
get /chats/messages
消息列表
-header;
{
token: "xxxxxxx";
}
-body;
{
*chatId: "xxxxxxxxxxxx", limit, skip, startAt, endAt;
}
res
{
code:200,
messages:[],
meta:{
limit,
skip,
...
}
}
post /chats/groups
新建群聊
-header;
{
token: "xxxxxxx";
}
-body;
{
users: [];
}
res
{
code:200,
}
get /chats/groups/:id
查看群组信息
res
{
code:200,
users:[]
}
get /chats
获取会话列表
-header;
{
token: "xxxxxxx";
}
res
{
code:200,
chats:[
{id:1,type:1,icon:'xxxxx',unRead:2(token),lastMessage:{
}}
]
}
models
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class Chat {
@PrimaryGeneratedColumn()
id: number;
@Column()
chatId: string; //uuid
@Column()
name: string;
@Column()
type: string; //聊天室 /群组
@Column()
groupId: string;
@Column()
userIds: _string;
}
@Entity()
export class Message {
@PrimaryGeneratedColumn()
id: number;
@Column()
chatId: string; //uuid
@Column()
content: json;
@Column()
type: string;
@Column()
xxxx: string;
}
@Entity()
export class Group {
@PrimaryGeneratedColumn()
id: number;
@Column()
chatId: string;
@Column()
type: string;
@Column()
name: string;
@Column()
icon: string;
@Column()
desc: string;
}
//group user 1:n
参考
国内产品
- http://www.shiku.co/docs/server/#/kuxin-sdk?id=%e6%9c%8d%e5%8a%a1%e7%ab%af%e9%9b%86%e6%88%90
- 腾讯云 https://cloud.tencent.com/document/product/269/1520
- 网易 http://dev.yunxin.163.com/docs/product/IM%E5%8D%B3%E6%97%B6%E9%80%9A%E8%AE%AF/%E6%9C%8D%E5%8A%A1%E7%AB%AFAPI%E6%96%87%E6%A1%A3/%E8%81%8A%E5%A4%A9%E5%AE%A4
国外产品
https://api.revechat.com/rest/ https://www.twilio.com/docs/chat/rest/channel-resource https://developers.google.com/hangouts/chat/how-tos/rest-api
https://sendbird.com/features/chat-messaging
https://chat-api.com/en/swagger.html (5) https://talkjs.com/docs/Reference/REST_API/Reference/Conversations.html