added to send message to telegram bot
This commit is contained in:
36
lib/api.ts
36
lib/api.ts
@@ -1,36 +0,0 @@
|
||||
import axios from "axios";
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_SITE_URL || "https://api.serenmebel.uz",
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
export async function sendContactMessage(payload: {
|
||||
name: string;
|
||||
phone: string;
|
||||
message?: string;
|
||||
productSlug?: string;
|
||||
lang?: "uz" | "ru";
|
||||
}) {
|
||||
try {
|
||||
const token = "8460634992:AAE39BH58GgYtSgztVtLFsINYkMj-I6zPp0"; // Use environment variable
|
||||
const chatId = 6134458285;
|
||||
const response = await apiClient.post("/api/contact", payload);
|
||||
await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
|
||||
chat_id: chatId,
|
||||
payload
|
||||
});
|
||||
return { success: true, data: response.data };
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.error || "Failed to send message",
|
||||
};
|
||||
}
|
||||
return { success: false, error: "Network error" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user