Documentation ¶
Overview ¶
Provides the data types for the routes matchinng
This package primaraly's purpose is to provide a router for implementing a webhook and conviniently handle the intent's fulfillment requests towards the webhook.
The Router implements' net/http Handler interface to serve Google Actions webhook requests that are provided in the routes. Creating a webhook is as simple as:
router := okgohook.NewRouter() router.HandleIntent("HelloWorld", func(aog.FulfillmentRequest) *aog.Fulfillmentresponse { ... }) http.Handle(router) // Other routers such as gorilla/mux can be used as well log.Fatal(http.ListenAndServe(":6060", nil))
The default router shall also respond the Google Health checks sent for analytics
Index ¶
- Constants
- type FulfillmentFunction
- type Matcher
- type Route
- type Router
- func (this *Router) Authorize(aud string, proxy ...string) *Router
- func (this *Router) HandleIntent(intent string, fn FulfillmentFunction) *Route
- func (this *Router) HealthCheck(fn FulfillmentFunction)
- func (this *Router) Proxy(url string)
- func (this *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
Constants ¶
const ACTIONS_INTENT_HEALTH_CHECK = "actions.intent.HEALTH_CHECK"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FulfillmentFunction ¶
type FulfillmentFunction func(fr *aog.FulfillmentRequest) *aog.FulfillmentResponse
Function type for processing Google actions' fulfillment requests These functions must return a pointer to the response so that the Router can Encode it and send the proper response back.
func MyHandler(fr *aog.FulfillmentRequest) *aog.FulfillmentResponse { return &aog.FulfillmentResponse{ Prompt: &aog.Prompt{ FirstSimple: &aog.Simple{ Speech: "Hello World", }, }, }
type Matcher ¶
type Matcher interface {
Matches(*aog.FulfillmentRequest) bool
}
A okgohook.Matcher can be used as a custom match for routes to match a given request. If the request is not to be processed by the route Matches shall return false, otherwise (yes or condition ignored) true.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route stores the action for an intent along with additional conditions such as conditions on handlers, locale or custom provided.
The when the route is matched (the intent is matched and all the matchers return true, then the funcion FulfillmentFunction is executed).
func (*Route) MatchCustomFunc ¶
func (this *Route) MatchCustomFunc(f func(*aog.FulfillmentRequest) bool) *Route
Adds a custom match function for the given intent to filter undesired requests for the given IntentHandler function
func (*Route) WithHandler ¶
Adds a condition to match the exact handler in the aog.FulfillmentRequest
Example usage:
myRouter.HandleIntent("hello_world", helloWolrdIntent).WithHandler("new-joiner")
func (*Route) WithHandlerLike ¶
Adds a condition to match the provided regular expression in the aog.FulfillmentRequest
Example usage:
myRouter.HandleIntent("hello_world", helloWolrdIntent).WithHandler(".*-joiner$")
func (*Route) WithLocaleLike ¶
Matches the locale of the fulfillment request to the provided regular expression
Example usage:
myRouter.HandleIntent("hello_world", helloWolrdIntent).WithLocaleLike("^EN-.*")
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router implements net/http's Handler interface to serve POST requests from Google Actions by serving the configured routes.
func NewRouter ¶
func NewRouter() *Router
NewRouter allocates and initializes a pointer to a Router struct adding also the default intent handlers.
var router *okgohook.Router router = okgohook.NewRouter()
func (*Router) Authorize ¶
Authorizes requests against the given audience. It also enables token verification and it launches a certificate retrieval goroutine. Only one proxy is accepted and if provided it shall be used to retrieve the certificates through it
func (*Router) HandleIntent ¶
func (this *Router) HandleIntent(intent string, fn FulfillmentFunction) *Route
HandleIntent creates a Route within the Router that shall be handled by fn.
Additional criterias can be added to the Route by using provided or custom Matchers.
Example:
myrouter.HandleIntent("hello_workld", func(fr *aog.FulfillmentRequest) *aog.FulfillmentResponse { return &aog.FulfillmentResponse { //...your hello world prompt goes here } }
func (*Router) HealthCheck ¶
func (this *Router) HealthCheck(fn FulfillmentFunction)
Function to replace the default provided health check intent.
It is likely this will never be required
Directories ¶
Path | Synopsis |
---|---|
The types provided in this package are for decoding and encoding the JSON objects set by the Actions on Google for a webhook The data types provided in this package are documented here: (https://developers.google.com/assistant/conversational/reference/rest/v1/TopLevel/fulfill As of now, this package does not implement all the types and further work is required.
|
The types provided in this package are for decoding and encoding the JSON objects set by the Actions on Google for a webhook The data types provided in this package are documented here: (https://developers.google.com/assistant/conversational/reference/rest/v1/TopLevel/fulfill As of now, this package does not implement all the types and further work is required. |