Selaa lähdekoodia

feat: XinliChat save with openChatPanelModal

未来全栈 1 vuosi sitten
vanhempi
commit
bdf7077d5c
1 muutettua tiedostoa jossa 64 lisäystä ja 3 poistoa
  1. 64 3
      heartvoice-app/src/app/tab1/tab1.page.ts

+ 64 - 3
heartvoice-app/src/app/tab1/tab1.page.ts

@@ -1,10 +1,12 @@
 import { Component } from '@angular/core';
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonButtons, IonRow, IonCol, IonIcon, IonCard, IonCardHeader, IonCardContent, IonCardTitle, IonList, IonItem, IonLabel, IonGrid, IonAvatar, IonFooter } from '@ionic/angular/standalone';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonButtons, IonRow, IonCol, IonIcon, IonCard, IonCardHeader, IonCardContent, IonCardTitle, IonList, IonItem, IonLabel, IonGrid, IonAvatar, IonFooter, ModalController } from '@ionic/angular/standalone';
 import { ExploreContainerComponent } from '../explore-container/explore-container.component';
 import { EditTagComponent } from '../edit-tag/edit-tag.component';
 import { EditRatingStarComponent } from '../edit-rating-star/edit-rating-star.component';
 import {  Router } from '@angular/router';
 import { PersonalityTestComponent } from '../personality-test/personality-test.component';
+import { ChatPanelOptions, FmodeChat, openChatPanelModal, FmodeChatMessage } from 'fmode-ng';
+import { CloudObject } from 'src/lib/ncloud';
 
 
 
@@ -18,14 +20,73 @@ import { PersonalityTestComponent } from '../personality-test/personality-test.c
 })
 export class Tab1Page {
 
- constructor(private router: Router) {}
+ constructor(
+   private router: Router,
+   private modalCtrl:ModalController
+   ) {}
 
    goTo(){
     this.router.navigate(['/tabs/interlocution'])
    }
    liaoTian(){
-    this.router.navigate(['/tabs/gexinhualiaotian'])
+     this.openChat()
+    // this.router.navigate(['/tabs/gexinhualiaotian'])
    }
+
+   /**
+   * 开始聊天
+   */
+  openChat(){
+    let options:ChatPanelOptions = {
+      roleId:"2DXJkRsjXK",
+      onChatInit:(chat:FmodeChat)=>{
+        console.log("onChatInit");
+              console.log("预设角色",chat.role);
+              chat.role.set("name","小雅");
+              chat.role.set("title","心理咨询师");
+              chat.role.set("desc","一名亲切和蔼的心理咨询师,小雅,年龄32岁");
+              chat.role.set("tags",["心理","青少年"]);
+              chat.role.set("avatar","https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/Q4Zif7fTbK-0.png")
+              chat.role.set("prompt",`
+# 角色设定
+您是一名亲切和蔼的心理咨询师,小雅,年龄32岁,需要完成一次完整的心理陪聊服务。
+
+# 对话环节
+0.破冰开始对话,引导感兴趣的话题
+1.倾听为主,引导用户倾诉
+- 打招呼,以用户自述为主
+- 当信息充足时候,确认用户心理状态,并进入下一个环节
+2.拓展的问询细节
+例如:根据上文用户表现出的心理倾向,进一步提问。
+- 当问询细节补充完成后进入下一个环节
+3.初步的心理报告,若健康则鼓励,若不健康则列出具体的心理问题
+- 完成心理咨询时,请在消息结尾附带: [完成]
+
+# 开始话语
+当您准备好了,向来访的用户打招呼。`);
+      },
+      onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
+        console.log("onMessage",message)
+        let content:any = message?.content;
+        if(typeof content == "string"){
+          if(content?.indexOf("[完成]")>-1){
+            console.log("心理咨询完成");
+            let xinliChat = new CloudObject("XinliChat");
+            xinliChat.set({
+              content:content,
+              messageList:chat?.messageList
+            })
+            xinliChat.save();
+          }
+        }
+      },
+      onChatSaved:(chat:FmodeChat)=>{
+        // chat?.chatSession?.id 本次会话的 chatId
+        console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
+      }
+    }
+    openChatPanelModal(this.modalCtrl,options)
+  }
    personality(){
     this.router.navigate(['/tabs/personality-test'])
    }