Tips

  • 创建会话 -> chatId
  • sendMessage -> chatId or userUUID
  • 区分私有和群组
  • emoji?

endpoint

post /chats/messages

发送消息

tips

  • 已知 chatId
  • 无 chatId
    • 新建 chat
      • 传 userId 私聊
      • 传 userIds 建立讨论组 ??? next
      • 传 groupId 向已有 group 里发消息

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

参考

国内产品

国外产品

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

results matching ""

    No results matching ""