Skip to content

Commit

Permalink
Add call-termination handling to Respond
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr1sh1 committed Mar 9, 2024
1 parent 958450a commit 4e5ac7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions functions/respond.protected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const handler: ServerlessFunctionSignature<TwilioEnvironmentVariables, Re
event,
callback
) {
if (event.CallStatus !== "in-progress") return callback(null)

const openai = ClientManager.getOpenAIClient(context)
const twiml_response = new Twilio.twiml.VoiceResponse();
const response = new Twilio.Response();
Expand Down
14 changes: 6 additions & 8 deletions functions/statusCallback.protected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ export const handler: ServerlessFunctionSignature<TwilioEnvironmentVariables, St
messages = messages.concat(page.getPaginatedItems())
}

const formattedMessages: Conversation = messages.flatMap(message => {
const splitMessages: MessageContentText[] = message.content.filter(isMessageContentText)
return splitMessages.map(singleMessage => {
return {
role: message.role,
content: singleMessage.text.value
}
})
const formattedMessages: Conversation = messages.map(message => {
const textMessage: MessageContentText = message.content.filter(isMessageContentText)[0]
return {
role: message.role,
content: textMessage.text.value
}
})

function isMessageContentText(message: MessageContentText | MessageContentImageFile): message is MessageContentText {
Expand Down

0 comments on commit 4e5ac7c

Please sign in to comment.