Back to

package apiai

v0.0.0 (d933019)
Latest Go to latest
Published: Dec 1, 2017 | License: Apache-2.0 | Module:


Package apiai provides an easy way to handle webhooks coming from, as described in the documentation:


func HTTPRequest

func HTTPRequest(ctx context.Context) *http.Request

HTTPRequest returns the HTTP request associated to the given context or nil.

type Handler

type Handler struct {
	// contains filtered or unexported fields

Handler provides an easy way to route and handle requests by intent.

func NewHandler

func NewHandler() *Handler

NewHandler returns a new empty handler.

func (*Handler) Register

func (h *Handler) Register(intent string, handler IntentHandler)

Register registers the handler for a given intent.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type IntentHandler

type IntentHandler func(ctx context.Context, req *Request) (*Response, error)

IntentHandler handles an intent.

type Request

type Request struct {
	Lang   string `json:"lang"`
	Status struct {
		ErrorType string `json:"errorType"`
		Code      int    `json:"code"`
	} `json:"status"`
	Timestamp time.Time `json:"timestamp"`
	SessionID string    `json:"sessionId"`
	Result    struct {
		Parameters    map[string]string `json:"parameters"`
		Contexts      []struct{}        `json:"contexts"` // TODO
		ResolvedQuery string            `json:"resolvedQuery"`
		Source        string            `json:"source"`
		Score         float64           `json:"score"`
		Speech        string            `json:"speech"`
		Fulfillment   struct {
			Messages []struct {
			} `json:"messages"`
			Speech string `json:"speech"`
		} `json:"fulfillment"`
		ActionIncomplete bool   `json:"actionIncomplete"`
		Action           string `json:"action"`
		Metadata         struct {
			IntentID                  string `json:"intentId"`
			WebhookForSlotFillingUsed bool   `json:"webhookForSlotFillingUsed,string"`
			IntentName                string `json:"intentName"`
			WebhookUsed               bool   `json:"webhookUsed,string"`
		} `json:"metadata"`
	} `json:"result"`
	ID              string `json:"id"`
	OriginalRequest struct {
		Source string                 `json:"source"`
		Data   map[string]interface{} `json:"data"` // TODO
	} `json:"originalRequest"`

A Request contains all of the information to an intent invocation.

func (*Request) Param

func (req *Request) Param(name string) string

Param returns the value associated to the given parameter name.

type Response

type Response struct {
	Speech      string `json:"speech"`
	DisplayText string `json:"displayText"`

A Response is what an intent responds after an invokation.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier