From 1355de8f966b24bccc5d570a4c82de5f61472657 Mon Sep 17 00:00:00 2001 From: sangeun0612 <146156429+sangeun0612@users.noreply.github.com> Date: Fri, 29 Nov 2024 05:24:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20gpt=20=EC=9D=91=EB=8B=B5=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=99=94=EB=A5=BC=20=EC=A2=85=EB=A3=8C=ED=95=9C?= =?UTF-8?q?=EB=8B=A4=EB=8A=94=20=EB=A9=94=EC=8B=9C=EC=A7=80=EA=B0=80=20?= =?UTF-8?q?=EC=9E=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=A0=84=ED=99=94=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=20=EC=A2=85=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server.js | 17 ++++++++++++++--- frontend/public/index.html | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/server.js b/backend/server.js index 4bfbd3e..47a312a 100644 --- a/backend/server.js +++ b/backend/server.js @@ -18,8 +18,6 @@ const twilio = require("twilio"); const app = express(); -// 테스트 - // JSON과 URL 자동 파싱 app.use(express.json()); app.use(express.urlencoded({extended: true})); @@ -27,6 +25,11 @@ 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'), @@ -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); @@ -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); // 상담 시작 메시지 출력 @@ -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; diff --git a/frontend/public/index.html b/frontend/public/index.html index aa069f2..bd3a537 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -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`. --> -