Created
January 11, 2018 09:18
-
-
Save JonJam/5a01d4c3aca0b6df2e0e3d36c7a9ad78 to your computer and use it in GitHub Desktop.
LUIS
This file contains hidden or 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 { ChatConnector, LuisRecognizer, UniversalBot } from "botbuilder"; | |
| import { appId, appPassword, luisAppUrl } from "../settings"; | |
| import colour from "./dialogs/colour"; | |
| import defaultDialog from "./dialogs/default"; | |
| // Create chat connector for communicating with the Bot Framework Service | |
| const connector = new ChatConnector({ | |
| appId, | |
| appPassword | |
| }); | |
| const bot = new UniversalBot(connector, defaultDialog); | |
| bot.recognizer(new LuisRecognizer(luisAppUrl)); | |
| bot.library(colour.clone()); | |
| export default connector; |
This file contains hidden or 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 { IPromptChoiceResult, Library, ListStyle, Prompts } from "botbuilder"; | |
| import { format } from "util"; | |
| import strings from "../../strings"; | |
| import { getColour, setColour } from "../data/userData"; | |
| const lib = new Library("colour"); | |
| lib | |
| .dialog("setFavourite", [ | |
| session => { | |
| session.sendTyping(); | |
| Prompts.choice( | |
| session, | |
| strings.colour.setFavourite.prompt, | |
| strings.colour.setFavourite.colours, | |
| { | |
| listStyle: ListStyle.auto, | |
| retryPrompt: strings.colour.setFavourite.retryPrompt | |
| } | |
| ); | |
| }, | |
| async (session, result: IPromptChoiceResult) => { | |
| // Removing undefined as choice prompt will ensure value. | |
| const chosenColor = result.response!.entity; | |
| setColour(session, chosenColor); | |
| const message = format( | |
| strings.colour.setFavourite.selection, | |
| chosenColor | |
| ); | |
| session.endDialog(message); | |
| } | |
| ]) | |
| .triggerAction({ | |
| // LUIS intent | |
| matches: "colour:setFavourite" | |
| }); | |
| lib | |
| .dialog("getFavourite", [ | |
| session => { | |
| session.sendTyping(); | |
| const chosenColor = getColour(session); | |
| let message = strings.colour.getFavourite.noFavourite; | |
| if (chosenColor !== undefined) { | |
| message = format(strings.colour.getFavourite.favourite, chosenColor); | |
| } | |
| session.endDialog(message); | |
| } | |
| ]) | |
| .triggerAction({ | |
| // LUIS intent | |
| matches: "colour:getFavourite" | |
| }); | |
| export default lib; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment