28 lines
783 B
TypeScript
28 lines
783 B
TypeScript
import axios from "../http-client";
|
|
import { messageSchema, type ChannelId, type Uuid } from "../types";
|
|
|
|
export async function paginatedMessages(channelId: ChannelId, limit: number, before: ChannelId | undefined) {
|
|
const response = await axios.get(`/channels/${channelId}/messages`, {
|
|
params: {
|
|
limit,
|
|
before,
|
|
},
|
|
});
|
|
|
|
return (response.data as unknown[]).map((value) => messageSchema.parse(value));
|
|
}
|
|
|
|
export async function sendMessage(channelId: ChannelId, content: string, attachments?: Uuid[]) {
|
|
const response = await axios.post(`/channels/${channelId}/messages`, {
|
|
content,
|
|
attachments,
|
|
});
|
|
|
|
return messageSchema.parse(response.data);
|
|
}
|
|
|
|
export default {
|
|
paginatedMessages,
|
|
sendMessage,
|
|
};
|