13
<p>public async getMasterIntent(userText: string, id?: string, idType?: string): Promise<any> {<br />
const masterIntentResponse: MasterIntentClassifierResponse = new MasterIntentClassifierResponse();</p>
<p> // Start classifyIntent, skip words retrieval, and handleCacheLogic in parallel<br />
const mlResponsePromise = this.classifyIntent(userText);<br />
const skipWordsPromise = this.configService.get<string[]>(`skipWords`) || [];<br />
const cacheLogicPromise = id && idType ? this.handleCacheLogic(masterIntentResponse, id, idType) : Promise.resolve();</p>
<p> // Await the classifyIntent and skipWords results<br />
const [mlResponse, skipWords] = await Promise.all([mlResponsePromise, skipWordsPromise]);</p>
<p> // Process the highLevelIntent and check if it should be skipped<br />
const highLevelIntent = mlResponse?.intents.length ? mlResponse.intents[0].toLowerCase().trim() : 'unknown';<br />
const isSkip = skipWords.some(word => highLevelIntent.toLowerCase().includes(word.toLowerCase()));</p>
<p> let intentResp: string[] | undefined;</p>
<p> // If not skipping, initiate getIntentAIData call in parallel with other operations<br />
if (highLevelIntent !== 'unknown' && !isSkip) {<br />
const intentAIDataPromise = this.getIntentAIData(userText, highLevelIntent);</p>
<p> // Await the intent AI data<br />
const response = await intentAIDataPromise;<br />
intentResp = response?.chat_response.split(',');<br />
masterIntentResponse.subIntent = intentResp.map((i: string) => i.toLowerCase().trim());<br />
} else {<br />
masterIntentResponse.subIntent = [highLevelIntent];<br />
}</p>
<p> masterIntentResponse.userText = userText;<br />
masterIntentResponse.statusFlags = {<br />
expeditedPrescriptionEligibleCount: -1,<br />
prescriptionEligibleCount: -1,<br />
cancelPrescriptionEligibleCount: -1,<br />
refillablePrescriptionEligibleCount: -1,<br />
transferPrescriptionEligibleCount: -1,<br />
prescriptionStatus: [],<br />
};</p>
<p> // Filter out 'help' from subIntents if necessary<br />
const valueToRemove = 'help';<br />
masterIntentResponse.subIntent =<br />
masterIntentResponse.subIntent.length > 1<br />
? masterIntentResponse.subIntent.filter((item) => item !== valueToRemove)<br />
: masterIntentResponse.subIntent;</p>
<p> // Wait for the cache logic if it was started earlier<br />
await cacheLogicPromise;</p>
<p> // Now, handle intent matching<br />
let matchedIntent: MatchedIntentResponse = await this.matchIntent(masterIntentResponse.subIntent);</p>
<p> if (masterIntentResponse.subIntent.includes('unknown')) {<br />
masterIntentResponse.intent = String(IntentClassEnum.INTENT_UNKNOWN);<br />
} else if (matchedIntent.matchedAttributes.mainIntent === 'multiintent') {<br />
matchedIntent = await this.matchExceptionIntent(masterIntentResponse.subIntent);<br />
}</p>
<p> masterIntentResponse.intent = matchedIntent.matchedAttributes.mainIntent;<br />
masterIntentResponse.fillerText = matchedIntent.partialFiller;<br />
masterIntentResponse.promptId = matchedIntent.matchedAttributes.promptID?.trim() || '-1';<br />
masterIntentResponse.templateId = matchedIntent.matchedAttributes.dataTemplate?.trim() || '-1';<br />
masterIntentResponse.ruleNo = matchedIntent.matchedAttributes.ruleNo?.trim() || '-1';<br />
masterIntentResponse.seqNo = matchedIntent.matchedAttributes.seqNo;</p>
<p> this.logger.addFunctionalTags('masterIntentResponse.intent', `${masterIntentResponse.intent}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.subIntent', `${masterIntentResponse.subIntent}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.fillerText', `${masterIntentResponse.fillerText}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.promptId', `${masterIntentResponse.promptId}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.templateId', `${masterIntentResponse.templateId}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.ruleId', `${matchedIntent.matchedAttributes.ruleNo}`);<br />
this.logger.addFunctionalTags('masterIntentResponse.seqNo', `${matchedIntent.matchedAttributes.seqNo}`);</p>
<p> return masterIntentResponse;<br />
}<br />
</p>