You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caleb Hiebert edited this page Nov 16, 2018
·
3 revisions
The intent router is a middleware that allows routing to different handlers based on the intent flag
Here is a code snippet showing how to use the intent router
funcmain() {
gobblr:=gbl.New()
gobblr.Use(gbl.RequestExtractionMiddleware())
// Create a dummy middleware to simulate an intentgobblr.Use(func(c*gbl.Context) {
c.Flag("intent", "hello")
c.Next()
})
// Create a new intent routerir:=gbl.IntentRouter()
// Add a handler for the "hello" intent// This handler will be called whenever the "intent" flag is set to "hello"ir.Intent("hello", func(c*gbl.Context) {
// When using the console integration, the context R (response) object// we need to cast it so we can use it's functionsbasicResponse:=c.R.(*gbl.BasicResponse)
// Add a text message to the outputbasicResponse.Text(fmt.Sprintf("Hello: %s", c.Request.Text))
})
// Make sure the bot is using the middleware generated by the routergobblr.Use(ir.Middleware())
ci:= gbl.ConsoleIntegration{}
ci.Listen(gobblr)
}