Last active
June 2, 2018 14:16
-
-
Save DanielNetzer/9f9cfce6e214b2937da2c38336045c58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose from 'mongoose'; | |
export interface CategoryAI { | |
utterances: Utterance[]; | |
entities: string[]; | |
} | |
export interface CategoryFilter { | |
entityName: string; | |
operatorOnValue: string; | |
operand: string; | |
} | |
export interface BotMessage { | |
messageType: BotMessageType; | |
message: string; | |
options?: Array<BotMessageOption>; | |
results?: Array<ProductDetails>; | |
} | |
export interface BotMessageOption { | |
name: string; | |
featuresAffected: Array<CategoryFilter>; | |
} | |
export interface ProductDetails { | |
platformId: string; | |
title: string; | |
price?: string | number; | |
imageUrl?: Array<string>; | |
viewUrl: string; | |
description: string; | |
} | |
export enum BotMessageType { | |
Opening = 0, | |
Text = 2, | |
Result = 4, | |
Action = 8 | |
} | |
export type BotCategoryModel = mongoose.Document & { | |
platformId: string; | |
domain: string; | |
name: string; | |
imageUrl: string; | |
description: string; | |
viewUrl: string; | |
ai: CategoryAI; | |
products: Array<ProductDetails>; | |
conversation: Array<BotMessage>; | |
}; | |
export interface Utterance { | |
text: string; | |
intentName: string; | |
entityLabels: EntityLabel[]; | |
} | |
export interface EntityLabel { | |
entityValue: string; | |
entityName: string; | |
startCharIndex: number; | |
endCharIndex: number; | |
} | |
const botCategorySchema = new mongoose.Schema({ | |
platformId: String, | |
name: String, | |
imageUrl: String, | |
description: String, | |
domain: String, | |
viewUrl: String, | |
ai: { | |
utterances: [{ | |
text: String, | |
intentName: String, | |
entityLabels: [{ | |
entityValue: String, | |
entityName: String, | |
startCharIndex: Number, | |
endCharIndex: Number | |
}] | |
}], | |
entities: [String] | |
}, | |
products: [{ | |
platformId: String, | |
title: String, | |
price: String || Number, | |
imageUrl: [String], | |
viewUrl: String, | |
description: String | |
}], | |
conversation: [{ | |
messageType: { type: String, enum: ['Opening', 'Text', 'Result', 'Action'] }, | |
message: String, | |
options: [{ | |
name: String, | |
featuresAffected: [{ | |
entityName: String, | |
operatorOnValue: String, | |
operand: String | |
}] | |
}], | |
results: [{ | |
title: String, | |
price: String || Number, | |
currency: String, | |
imageUrl: [String], | |
resultPageUrl: String | |
}] | |
}] | |
}, { timestamps: true }); | |
botCategorySchema.set('toJSON', { | |
virtuals: true, | |
versionKey: false, | |
transform: (doc: mongoose.Document, ret: any) => { delete ret._id; } | |
}); | |
const BotCategory = mongoose.model('BotCategory', botCategorySchema); | |
export default BotCategory; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment