Skip to content

Commit

Permalink
feat: gpt 응답에 대화를 종료한다는 메시지가 있을 경우 전화 자동 종료
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeun0612 committed Nov 28, 2024
1 parent ec3c4b8 commit 1355de8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ const twilio = require("twilio");

const app = express();

// 테스트

// JSON과 URL 자동 파싱
app.use(express.json());
app.use(express.urlencoded({extended: true}));

// React 정적 파일 제공
app.use(express.static(path.join(__dirname, '../frontend/build')));

// Twilio Client 초기화
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const twilioClient = twilio(accountSid, authToken);

// SSL 인증서와 개인 키 읽기
const options = {
cert: fs.readFileSync('/etc/letsencrypt/live/welfarebot.kr/fullchain.pem'),
Expand Down Expand Up @@ -186,6 +189,7 @@ httpsServer.on('upgrade', (request, socket, head) => {
let isAudioProcessing = true;
let chatModelResponse = null;
let phoneNumber = null;
let callSid = null;

wsTwilio.on('message', message => {
const msg = JSON.parse(message);
Expand All @@ -196,6 +200,7 @@ httpsServer.on('upgrade', (request, socket, head) => {
case "start":
phoneNumber = msg.start.customParameters.phoneNumber;
const gptRequest = msg.start.customParameters.gptRequest;
callSid = msg.start.callSid;
console.log("\n전화번호", phoneNumber);

// 상담 시작 메시지 출력
Expand Down Expand Up @@ -297,8 +302,14 @@ httpsServer.on('upgrade', (request, socket, head) => {
}
break;

case "mark":
case "mark":
playBeepSound(wsTwilio, msg.streamSid); //삐 소리 출력
// "대화를 종료"라는 텍스트가 포함되어 있는지 확인
(async () => {
if (chatModelResponse.includes("대화를 종료")) {
await twilioClient.calls(callSid).update({status: 'completed'});
}
}) ();
isAudioProcessing = false;
recognizeStream = null;
break;
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>복지봇(Silver)</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down

0 comments on commit 1355de8

Please sign in to comment.