in frontend/src/app/customer/df-messenger/df-messenger.component.ts [54:136]
onMessageReceived(event: any) {
event.detail.messages.forEach(async (message: any) => {
console.log(message.type);
if (message.type === 'customCard') {
if ('parameters' in event.detail.raw.queryResult) {
if ('date-time' in event.detail.raw.queryResult.parameters) {
const dateTime = event.detail.raw.queryResult.parameters['date-time'];
const today: Date = new Date();
const startTime: Date = new Date(
dateTime.year || today.getFullYear(),
dateTime.month - 1 || today.getMonth(),
dateTime.day || today.getDay(),
dateTime.hours || 12,
dateTime.minutes || 0,
dateTime.seconds || 0);
const firestoreDateTime: Timestamp = Timestamp.fromDate(startTime);
firstValueFrom(this.fieldServiceAgentService.generateAgentActivity(this.userId, "2", this.conversation, firestoreDateTime));
const scheduleResponse: any = await firstValueFrom(
this.fieldServiceAgentService.scheduleEvent(
[this.userEmail], startTime.toISOString().split(".")[0] + 'Z'
) as Observable<any>);
const payload = [
{
"icon": {
"color": "#FF9800",
"type": "chevron_right"
},
"event": {
"event": ""
},
"type": "button",
"mode": "blocking",
"anchor": {
"href": scheduleResponse.calendar_link
},
"text": "Go to Calendar link"
}
]
const dfMessenger: any = document.querySelector('df-messenger');
dfMessenger.renderCustomCard(payload);
}
}
if ('intent' in event.detail.raw.queryResult) {
if ('displayName' in event.detail.raw.queryResult.intent) {
if (event.detail.raw.queryResult.intent.displayName = "Talk to human agent") {
const chatMessage: ChatMessage = {
author: "Agent",
language: "en-US",
text: "Hi, I will check the chat history and answer you in a few moments",
}
this.conversationList.push(chatMessage);
console.log(event.detail.raw.queryResult.intent.displayName);
let res: any = await firstValueFrom(this.customerServiceAgentService.addMessage(this.userId, "new", this.conversationList[0]));
if (this.conversationList.length > 1) {
for (let index = 1; index < this.conversationList.length; index++) {
res = await firstValueFrom(this.customerServiceAgentService.addMessage(this.userId, res.conversation_id, this.conversationList[index]));
}
}
}
}
}
} else if (message.type === 'text') {
this.conversation += "Virtual Support Agent: ";
this.conversation += message.text;
this.conversation += "\n";
const chatMessage: ChatMessage = {
author: "Agent",
language: "en-US",
text: message.text,
}
this.conversationList.push(chatMessage);
}
});
console.log(event);
}