-setupchat
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { GeneralService } from './../../services/generalservice';
|
||||
import { ReactiveFormsModule, FormGroup, FormControl, Validators } from '@angular/forms';
|
||||
import { IChat } from '../../interfaces/main.interface'
|
||||
import { Component, HostListener } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
@@ -11,6 +13,7 @@ export class ChatWidgetComponent {
|
||||
isOpen = false;
|
||||
// newMessage = '';
|
||||
chatForm!: FormGroup;
|
||||
messages:IChat[]=[];
|
||||
|
||||
// State สำหรับจัดการขนาด
|
||||
isMaximized = false;
|
||||
@@ -27,7 +30,9 @@ export class ChatWidgetComponent {
|
||||
private startHeight = 0;
|
||||
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
private generalService: GeneralService
|
||||
) {
|
||||
this.setupFormControl(); // เรียกใช้ตอนเริ่ม Component
|
||||
}
|
||||
|
||||
@@ -38,14 +43,42 @@ export class ChatWidgetComponent {
|
||||
}
|
||||
|
||||
|
||||
messages = [
|
||||
{ text: 'สวัสดีครับ AI พร้อมช่วยเหลือครับ 👋', isUser: false },
|
||||
{ text: 'ลองกดปุ่มขยายที่หัวมุม หรือลากมุมซ้ายบนของกล่องเพื่อปรับขนาดได้เลยครับ', isUser: false },
|
||||
];
|
||||
|
||||
toggleChat() {
|
||||
this.isOpen = !this.isOpen;
|
||||
this.isMaximized = false; // Reset ขนาดเมื่อปิด
|
||||
let body = {methods: 'ind'}
|
||||
this.OnAiChat(body);
|
||||
const isAlreadyHave = this.messages.some(sub => sub.text == 'รอAi ประมวณผลสักครู่');
|
||||
if(isAlreadyHave === false){
|
||||
this.messages.push({
|
||||
text: 'รอAi ประมวณผลสักครู่',
|
||||
isUser: false
|
||||
})
|
||||
}
|
||||
this.isMaximized = false;
|
||||
}
|
||||
|
||||
OnAiChat(value: any){
|
||||
let url = 'https://n8n.nuttakit.work/webhook/Ai'
|
||||
let request = {
|
||||
methods: value.methods || 'cht',
|
||||
message: value.message ?? ''
|
||||
}
|
||||
this.generalService.postUrl(url, request).subscribe({
|
||||
next: (result: any) => {
|
||||
if (result.code === 200) {
|
||||
this.messages.push(result.data)
|
||||
}else{
|
||||
this.generalService.trowApi(result);
|
||||
}
|
||||
},
|
||||
error: (error: any) => {
|
||||
|
||||
},
|
||||
complete: () => {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
toggleMaximize() {
|
||||
@@ -57,12 +90,12 @@ export class ChatWidgetComponent {
|
||||
if (newMessage.trim()) {
|
||||
this.messages.push({ text: newMessage, isUser: true });
|
||||
newMessage = '';
|
||||
setTimeout(() => {
|
||||
this.messages.push({
|
||||
text: 'รับทราบครับ ระบบกำลังประมวลผล...',
|
||||
isUser: false
|
||||
});
|
||||
}, 1000);
|
||||
// setTimeout(() => {
|
||||
// this.messages.push({
|
||||
// text: 'รับทราบครับ ระบบกำลังประมวลผล...',
|
||||
// isUser: false
|
||||
// });
|
||||
// }, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user