|
@@ -233,5 +233,68 @@ export const sendMessage = async (token: string = '', channel_id: string, messag
|
|
|
throw error;
|
|
|
}
|
|
|
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+export const updateMessage = async (token: string = '', channel_id: string, message_id: string, message: MessageForm) => {
|
|
|
+ let error = null;
|
|
|
+
|
|
|
+ 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 })
|
|
|
+ })
|
|
|
+ .then(async (res) => {
|
|
|
+ if (!res.ok) throw await res.json();
|
|
|
+ return res.json();
|
|
|
+ })
|
|
|
+ .then((json) => {
|
|
|
+ return json;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ error = err.detail;
|
|
|
+ console.log(err);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (error) {
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+export const deleteMessage = async (token: string = '', channel_id: string, message_id: string) => {
|
|
|
+ let error = null;
|
|
|
+
|
|
|
+ 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}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(async (res) => {
|
|
|
+ if (!res.ok) throw await res.json();
|
|
|
+ return res.json();
|
|
|
+ })
|
|
|
+ .then((json) => {
|
|
|
+ return json;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ error = err.detail;
|
|
|
+ console.log(err);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (error) {
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+
|
|
|
return res;
|
|
|
}
|