2024-12-22 11:10:10 +00:00
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
|
|
|
|
|
|
|
|
|
type ChannelForm = {
|
2025-11-27 12:27:32 +00:00
|
|
|
type?: string;
|
2024-12-22 11:10:10 +00:00
|
|
|
name: string;
|
2025-11-30 13:24:27 +00:00
|
|
|
is_private?: boolean;
|
2024-12-22 11:10:10 +00:00
|
|
|
data?: object;
|
|
|
|
|
meta?: object;
|
|
|
|
|
access_control?: object;
|
2025-11-27 12:27:32 +00:00
|
|
|
user_ids?: string[];
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-22 11:10:10 +00:00
|
|
|
|
|
|
|
|
export const createNewChannel = async (token: string = '', channel: ChannelForm) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/create`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...channel })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-22 11:10:10 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getChannels = async (token: string = '') => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-22 11:10:10 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
2024-12-23 02:40:01 +00:00
|
|
|
|
2024-12-23 05:20:24 +00:00
|
|
|
export const getChannelById = async (token: string = '', channel_id: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
2025-11-30 16:04:06 +00:00
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getDMChannelByUserId = async (token: string = '', user_id: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/users/${user_id}`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
2024-12-23 05:20:24 +00:00
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 05:20:24 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 05:20:24 +00:00
|
|
|
|
2025-11-27 12:27:32 +00:00
|
|
|
export const getChannelMembersById = async (
|
2025-11-25 09:38:07 +00:00
|
|
|
token: string,
|
|
|
|
|
channel_id: string,
|
|
|
|
|
query?: string,
|
|
|
|
|
orderBy?: string,
|
|
|
|
|
direction?: string,
|
|
|
|
|
page = 1
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
let res = null;
|
|
|
|
|
|
|
|
|
|
const searchParams = new URLSearchParams();
|
|
|
|
|
|
|
|
|
|
searchParams.set('page', `${page}`);
|
|
|
|
|
|
|
|
|
|
if (query) {
|
|
|
|
|
searchParams.set('query', query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orderBy) {
|
|
|
|
|
searchParams.set('order_by', orderBy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (direction) {
|
|
|
|
|
searchParams.set('direction', direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = await fetch(
|
2025-11-27 12:27:32 +00:00
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/members?${searchParams.toString()}`,
|
2025-11-25 09:38:07 +00:00
|
|
|
{
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
error = err.detail;
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-27 12:27:32 +00:00
|
|
|
export const updateChannelMemberActiveStatusById = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
is_active: boolean
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/members/active`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ is_active })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-30 15:33:50 +00:00
|
|
|
type UpdateMembersForm = {
|
|
|
|
|
user_ids?: string[];
|
|
|
|
|
group_ids?: string[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const addMembersById = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
formData: UpdateMembersForm
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/update/members/add`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...formData })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type RemoveMembersForm = {
|
|
|
|
|
user_ids?: string[];
|
|
|
|
|
group_ids?: string[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const removeMembersById = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
formData: RemoveMembersForm
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/update/members/remove`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...formData })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
export const updateChannelById = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
channel: ChannelForm
|
|
|
|
|
) => {
|
2024-12-23 06:09:51 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/update`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...channel })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 06:09:51 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 06:09:51 +00:00
|
|
|
|
2024-12-23 06:15:29 +00:00
|
|
|
export const deleteChannelById = async (token: string = '', channel_id: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/delete`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 06:15:29 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 05:20:24 +00:00
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
export const getChannelMessages = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
skip: number = 0,
|
|
|
|
|
limit: number = 50
|
|
|
|
|
) => {
|
2024-12-23 02:40:01 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages?skip=${skip}&limit=${limit}`,
|
|
|
|
|
{
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
2024-12-23 02:40:01 +00:00
|
|
|
}
|
2024-12-23 08:25:25 +00:00
|
|
|
)
|
2024-12-23 02:40:01 +00:00
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 02:40:01 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 02:40:01 +00:00
|
|
|
|
2025-11-28 14:58:44 +00:00
|
|
|
export const getChannelPinnedMessages = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
page: number = 1
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/pinned?page=${page}`,
|
|
|
|
|
{
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-31 08:51:43 +00:00
|
|
|
export const getChannelThreadMessages = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
message_id: string,
|
|
|
|
|
skip: number = 0,
|
|
|
|
|
limit: number = 50
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/thread?skip=${skip}&limit=${limit}`,
|
|
|
|
|
{
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-31 08:51:43 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-31 10:26:30 +00:00
|
|
|
};
|
2024-12-31 08:51:43 +00:00
|
|
|
|
2024-12-23 02:40:01 +00:00
|
|
|
type MessageForm = {
|
2025-11-28 15:45:48 +00:00
|
|
|
temp_id?: string;
|
2025-09-27 09:05:12 +00:00
|
|
|
reply_to_id?: string;
|
2024-12-31 10:05:11 +00:00
|
|
|
parent_id?: string;
|
2024-12-23 02:40:01 +00:00
|
|
|
content: string;
|
|
|
|
|
data?: object;
|
2024-12-23 08:25:25 +00:00
|
|
|
meta?: object;
|
|
|
|
|
};
|
2024-12-23 02:40:01 +00:00
|
|
|
|
|
|
|
|
export const sendMessage = async (token: string = '', channel_id: string, message: MessageForm) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/post`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...message })
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
2025-11-28 14:58:44 +00:00
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
|
|
|
|
console.error(err);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const pinMessage = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
message_id: string,
|
|
|
|
|
is_pinned: boolean
|
|
|
|
|
) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/pin`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ is_pinned })
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
2024-12-23 02:40:01 +00:00
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 02:40:01 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 08:12:55 +00:00
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 08:12:55 +00:00
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
export const updateMessage = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
message_id: string,
|
|
|
|
|
message: MessageForm
|
|
|
|
|
) => {
|
2024-12-23 08:12:55 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/update`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ ...message })
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-12-23 08:12:55 +00:00
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 08:12:55 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|
2024-12-23 08:12:55 +00:00
|
|
|
|
2024-12-31 10:26:30 +00:00
|
|
|
export const addReaction = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
message_id: string,
|
|
|
|
|
name: string
|
|
|
|
|
) => {
|
2024-12-31 07:06:34 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/reactions/add`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ name })
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-31 07:06:34 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-31 10:26:30 +00:00
|
|
|
};
|
2024-12-31 07:06:34 +00:00
|
|
|
|
2024-12-31 10:26:30 +00:00
|
|
|
export const removeReaction = async (
|
|
|
|
|
token: string = '',
|
|
|
|
|
channel_id: string,
|
|
|
|
|
message_id: string,
|
|
|
|
|
name: string
|
|
|
|
|
) => {
|
2024-12-31 07:06:34 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/reactions/remove`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ name })
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-31 07:06:34 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2024-12-31 10:26:30 +00:00
|
|
|
};
|
2024-12-31 07:06:34 +00:00
|
|
|
|
2024-12-23 08:12:55 +00:00
|
|
|
export const deleteMessage = async (token: string = '', channel_id: string, message_id: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
2024-12-23 08:25:25 +00:00
|
|
|
const res = await fetch(
|
|
|
|
|
`${WEBUI_API_BASE_URL}/channels/${channel_id}/messages/${message_id}/delete`,
|
|
|
|
|
{
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
|
}
|
2024-12-23 08:12:55 +00:00
|
|
|
}
|
2024-12-23 08:25:25 +00:00
|
|
|
)
|
2024-12-23 08:12:55 +00:00
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json) => {
|
|
|
|
|
return json;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
error = err.detail;
|
2025-05-15 19:35:07 +00:00
|
|
|
console.error(err);
|
2024-12-23 08:12:55 +00:00
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 02:40:01 +00:00
|
|
|
return res;
|
2024-12-23 08:25:25 +00:00
|
|
|
};
|