diff --git a/src/api/call.js b/src/api/call.js index 44db02c..35cb6ec 100644 --- a/src/api/call.js +++ b/src/api/call.js @@ -19,6 +19,7 @@ import { transferSession, checkOperatorReady, postSummary, + completeCall, } from "../lib/session.js"; import { chat, summarize } from "../lib/chat.js"; @@ -41,7 +42,10 @@ app.post("/receive", async (req, res) => { model: "experimental_conversations", }); - gather.say("Welcome to the suicide hotline. Tell me what's going on?."); + gather.say( + { voice: "Polly.Salli" }, + "Welcome to the Suicide Prevention Hotline. You have reached a virtual resource where you can talk through your problems in a safe and supportive environment. Please know that you are not alone, and help is available. How are you feeling right now?" + ); console.log(twiml.toString()); @@ -67,7 +71,10 @@ app.post("/respond", async (req, res) => { console.log(`transferring call ${callId} to ${operatorPhone}`); transferSession(req.body.CallSid, operatorPhone); - twiml.say("We're connecting you to a counselor now."); + twiml.say( + { voice: "Polly.Sali" }, + "We're connecting you to a counselor now." + ); const dial = twiml.dial({}); dial.number(operatorPhone); @@ -87,7 +94,7 @@ app.post("/respond", async (req, res) => { let response = await chat(callId); - gather.say(response); + gather.say({ voice: "Polly.Salli" }, response); await addMessage(callId, Role.BOT, response); twiml.redirect("/call/respond"); @@ -109,4 +116,14 @@ app.post("/summarize", async (req, res) => { res.send(JSON.stringify({ SessionId: sessionId, summary: summary })); }); +app.post("/status", async (req, res) => { + let callId = req.body.CallSid; + let callStatus = req.body.CallStatus; + + if (callStatus === "completed") { + console.log(`completing call ${callId}`); + await completeCall(callId); + } +}); + export default app; diff --git a/src/lib/chat.js b/src/lib/chat.js index b832cda..b6781ca 100644 --- a/src/lib/chat.js +++ b/src/lib/chat.js @@ -29,7 +29,7 @@ export const chat = async (callId) => { { role: "system", content: - "ChatGPT, for the following conversation, please pretend to be a therapist working at a suicide prevention hotline. Respond as if I've called you. Limit your responses to 20 seconds, and don't recommend that they seek other help. Make sure you continue the conversation by ending every response with a question.", + "ChatGPT, for the following conversation, please pretend to be a therapist working at a suicide prevention hotline. Respond as if I've called you. Limit your responses to 20 seconds. Don't recommend that they seek other help. Don't ask if they've spoken to a specialist about the issue yet. Make sure you continue the conversation by ending every response with a question.", }, ]; diff --git a/src/lib/session.js b/src/lib/session.js index 3b2b4e7..adba470 100644 --- a/src/lib/session.js +++ b/src/lib/session.js @@ -21,6 +21,17 @@ export const findSessionByCallId = async (callId) => { }); }; +export const completeCall = async (callId) => { + return await db.session.update({ + where: { + callId: callId, + }, + data: { + endedAt: new Date(), + }, + }); +}; + export const transferSession = async (callId, operatorPhone) => { return await db.session.update({ where: {