You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.4 KiB

import axios, { AxiosInstance, AxiosError } from 'axios';
// Chat API base URL
const CHAT_API_BASE_URL = 'https://6454c61f-3a39-43f7-afb1-d342c903b84e-00-21kfz12hqvw76.sisko.replit.dev';
// Create axios instance for chat
const chatApi: AxiosInstance = axios.create({
baseURL: CHAT_API_BASE_URL,
timeout: 30000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
// Request interceptor
chatApi.interceptors.request.use(
async (config) => {
return config;
},
(error) => {
return Promise.reject(error);
}
);
// Response interceptor
chatApi.interceptors.response.use(
(response) => {
return response;
},
(error: AxiosError) => {
return Promise.reject(error);
}
);
// API methods
export const chatService = {
// Send message
async sendMessage(newMessage: {
type: string,
mimetype: string,
userWs: string,
app_id: string,
country: string,
body: string,
text: string
}): Promise<any> {
try {
const response = await chatApi.post('/chat', { newMessage });
return response.data;
} catch (error) {
throw error;
}
},
// Get chat history
async getChatHistory(sessionId: string): Promise<any> {
try {
const response = await chatApi.get('/history', { params: { sessionId } });
return response.data;
} catch (error) {
throw error;
}
}
};
export default chatApi;