Skip to content
Caleb Hiebert edited this page Nov 22, 2018 · 5 revisions

Here is a small code snippet showing you how to use the LUIS integration

func main() {

	// Create a new LUIS instance, this will store everything needed to access LUIS
	// This will return an error if the subscription-key query parameter is missing
	// Replace LUIS_ENDPOINT with your actual LUIS endpoint
	louie, err := luis.New("LUIS_ENDPOINT")
	if err != nil {
		panic(err)
	}

	// Create a new bot
	gobblr := gbl.New()

	gobblr.Use(gbl.UserExtractionMiddleware())
	gobblr.Use(gbl.RequestExtractionMiddleware())
	gobblr.Use(luis.Middleware(louie))

	gobblr.Use(func(c *gbl.Context) {

		// The LUIS integration will set the "intent" flag equal
                // to the name of the top scoring intent
		intent := c.GetFlag("intent").(string)

		// The LUIS integration will also store the entire
                // result in the "luis" flag
		luisResult := c.GetFlag("luis").(*luis.Response)

		fmt.Printf("LUIS\n%+v\n", luisResult)

		// If this looks weird, check out the page about the Console integration
		c.R.(*gbl.BasicResponse).Text(fmt.Sprintf("The intent is: %s", intent))
	})

	ci := gbl.ConsoleIntegration{}
	ci.Listen(gobblr)
}

Clone this wiki locally