Skip to content

Commit

Permalink
removing links from responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amruth-Vamshi committed Dec 6, 2023
1 parent 0623c3f commit f1320ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { interpret } from "xstate";
import { Language } from "./language";
import { ConfigService } from "@nestjs/config";
import { AiToolsService } from "./modules/aiTools/ai-tools.service";
import { formatStringsToTable, wordToNumber } from "./common/utils";
import { formatStringsToTable, removeLinks, wordToNumber } from "./common/utils";
import { ConversationService } from "./modules/conversation/conversation.service";
import { PrismaService } from "./global-services/prisma.service";
import { CustomLogger } from "./common/logger";
Expand Down Expand Up @@ -1010,6 +1010,7 @@ export class AppController {
}
// verboseLogger("textToaudio =",textToaudio)
let audioStartTime = Date.now();
textToaudio = removeLinks(textToaudio)
result['audio'] = await this.aiToolsService.textToSpeech(textToaudio,isNumber ? Language.en : prompt.inputLanguage)
if(result['audio']['error']){
await this.telemetryService.capture({
Expand Down
8 changes: 8 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,12 @@ export const wordToNumber = (input,type='benId') => {
return number + "th";
}
}
}

export const removeLinks = (inputString) => {
// Define a regular expression pattern for identifying links
var linkPattern = /http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/g;
// Use the replace() method to replace all links with an empty string
var resultString = inputString.replace(linkPattern, '');
return resultString;
}
12 changes: 6 additions & 6 deletions src/xstate/prompt/prompt.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ export const botFlowMachine3:any =
actions: [
assign({
response: () => engMessage["message.convoStarter"],
type:"pause"
type:"pause",
isWadhwaniResponse: "false"
})
]
},
Expand All @@ -899,7 +900,8 @@ export const botFlowMachine3:any =
target: 'checkIfOTPHasBeenVerified',
actions: [
assign({
queryType: (_,event) => {console.log(`assigning queryType = ${event.data}`); return event.data}
queryType: (_,event) => {console.log(`assigning queryType = ${event.data}`); return event.data},
isWadhwaniResponse: "false"
})
]
}
Expand All @@ -926,8 +928,7 @@ export const botFlowMachine3:any =
userAadhaarNumber: "",
lastAadhaarDigits: "",
isOTPVerified: false,
type: '',
isWadhwaniResponse: "false"
type: ''
})
]
},
Expand All @@ -939,8 +940,7 @@ export const botFlowMachine3:any =
lastAadhaarDigits: "",
isOTPVerified: false,
error: (_, event) => event.data.message,
type: '',
isWadhwaniResponse: "false"
type: ''
})
]
}
Expand Down

0 comments on commit f1320ee

Please sign in to comment.