feat: fetch suggestions and scroll if required

This commit is contained in:
Shivam Mishra
2023-07-10 15:04:28 +05:30
parent 0ff3680fea
commit 5b1c89eabb
2 changed files with 49 additions and 1 deletions
@@ -1,5 +1,6 @@
import { mapGetters } from 'vuex';
import { OPEN_AI_EVENTS } from '../helper/AnalyticsHelper/events';
import OpenAPI from '../api/integrations/openapi';
export default {
mounted() {
@@ -33,5 +34,30 @@ export default {
});
}
},
async fetchLabelSuggestions({ conversationId }) {
try {
const result = await OpenAPI.processEvent({
type: 'label_suggestion',
hookId: this.hookId,
conversationId: conversationId,
});
const {
data: { message: labels },
} = result;
return this.cleanLabels(labels);
} catch (error) {
return [];
}
},
cleanLabels(labels) {
return labels
.toLowerCase() // Set it to lowercase
.split(',') // split the string into an array
.filter(label => label.trim()) // remove any empty strings
.filter((label, index, self) => self.indexOf(label) === index) // remove any duplicates
.map(label => label.trim()); // trim the words
},
},
};