added to send message to telegram bot

This commit is contained in:
nabijonovdavronbek619@gmail.com
2025-12-24 14:53:52 +05:00
parent fed245bfa3
commit d426b27359
2 changed files with 24 additions and 52 deletions

View File

@@ -3,11 +3,11 @@
import { useState } from "react";
import { motion } from "framer-motion";
import { usePathname } from "next/navigation";
import { sendContactMessage } from "@/lib/api";
import { Phone, MessageSquare, MapPin } from "lucide-react";
import Image from "next/image";
import { useLanguage } from "@/context/language-context";
import { useProductStore } from "@/lib/productZustand";
import axios from "axios";
export function ContactForm() {
const { t } = useLanguage();
@@ -45,18 +45,26 @@ export function ContactForm() {
setLoading(true);
setMessage(null);
try {
const result = await sendContactMessage({
...formData,
lang: locale,
});
const text = `
📩 New Contact Message
if (result.success) {
setMessage({ type: "success", text: t.contact.success });
setFormData({ name: "", phone: "", message: "", productName: "" });
} else {
setMessage({ type: "error", text: t.contact.error });
}
👤 Name: ${formData.name}
📞 Phone: ${formData.phone}
📦 Product: ${formData.productName || ""}
💬 Message:
${formData.message || "—"}
`;
try {
const token = "8242045471:AAHaECS0psWg1jGBaIk1GxxTG6sBAssK_vw"; // Use environment variable
const chatId = 6134458285;
await axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
chat_id: chatId,
text: text,
});
setMessage({ type: "success", text: t.contact.success });
} catch {
setMessage({ type: "error", text: t.contact.error });
} finally {
@@ -163,7 +171,7 @@ export function ContactForm() {
value={formData.name}
onChange={handleChange}
placeholder={t.contact.namePlaceholder}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
@@ -179,7 +187,7 @@ export function ContactForm() {
onChange={handleChange}
placeholder={t.contact.phonePlaceholder}
required
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
@@ -194,7 +202,7 @@ export function ContactForm() {
onChange={handleChange}
placeholder={t.contact.messagePlaceholder}
rows={4}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
/>
</div>
@@ -209,7 +217,7 @@ export function ContactForm() {
value={productName ? productName : formData.productName}
onChange={handleChange}
placeholder={t.contact.product}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
className="w-full px-4 py-2 border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>