dialogflow

package module
v2.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2018 License: MIT Imports: 9 Imported by: 2

README

A Go framework for building fulfillment services for DialogFlow intents.

GoDoc

Built with go-kit and NYTimes/gizmo.

For an example of this framework in action, check out NYC Train Time.

Documentation

Overview

Package dialogflow is a framework for building services that respond to DialogFlow fulfillment webhooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(svc FulfillmentService) error

Run will register a service with kit and run the server. Call this in your main function.

The service will register the webhook on the path "/fulfillment" so make sure to configure your fulfillment webhook to point at something like: https://example.appspot.com/fulfillment

Types

type EventInput

type EventInput struct {
	Name         string                 `json:"name"`
	LanguageCode string                 `json:"languageCode"`
	Parameters   map[string]interface{} `json:"parameters"`
}

EventInput will hold all inbound input information.

type FulfillmentMessage

type FulfillmentMessage struct {
	Text []string `json:"text"`
}

FulfillmentMessage is the most basic way to respond to intents.

type FulfillmentPayload

type FulfillmentPayload struct {
	Google   RichFulfillmentPayload `json:"google"`
	Facebook FulfillmentMessage     `json:"facebook"`
	Slack    FulfillmentMessage     `json:"slack"`
}

FulfillmentPayload allows users to respond differently to alternate platforms.

type FulfillmentResponse

type FulfillmentResponse struct {
	FulfillmentText     string               `json:"fulfillmentText"`
	FulfillmentMessages []FulfillmentMessage `json:"fulfillmentMessages"`
	Source              string               `json:"source"`
	Payload             *FulfillmentPayload  `json:"payload"`
	OutputContexts      []OutputContext      `json:"outputContexts"`
	FollowupEventInput  *EventInput          `json:"followupEventInput"`
}

FulfillmentResponse contains all the fields required for responding to a Dialogflow intent. For more information about how to fill this struct, see the documentation at: https://dialogflow.com/docs/fulfillment/how-it-works.

type FulfillmentService

type FulfillmentService interface {
	// Intents returns a mapping of intent display name IntentHandler.
	Intents() map[string]IntentHandler

	// Middleware can be used for things like adding generic responses or
	// authentication.
	Middleware(endpoint.Endpoint) endpoint.Endpoint
}

FulfillmentService returns a IntentHandler for each intent in their DialogFlow.

type Intent

type Intent struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
}

Intent contains the name that matched the user's query.

type IntentHandler

type IntentHandler func(context.Context, *Request) (*FulfillmentResponse, error)

IntentHandler encapsulates the logic for a single action for a Dialogflow intent. For more information about the request and response, see the DialogFlow documentation for fulfillment: https://dialogflow.com/docs/fulfillment/how-it-works

type OutputContext

type OutputContext struct {
	Name          string                 `json:"name"`
	LifespanCount int                    `json:"lifespanCount"`
	Parameters    map[string]interface{} `json:"parameters"`
}

OutputContext holds information for output contexts within fulfillment requests and responses.

type QueryResult

type QueryResult struct {
	LanguageCode             string                 `json:"languageCode"`
	QueryText                string                 `json:"queryText"`
	FulfillmentText          string                 `json:"fulfillmentText"`
	Action                   string                 `json:"action"`
	AllRequiredParamsPresent bool                   `json:"allRequiredParamsPresent"`
	Parameters               map[string]interface{} `json:"parameters"`
	OutputContexts           []OutputContext        `json:"outputContexts"`
	Intent                   Intent                 `json:"intent"`
	FulfillmentMessages      []struct {
		Text struct {
			Text []string `json:"text"`
		} `json:"text"`
	} `json:"fulfillmentMessages"`
	IntentDetectionConfidence float64     `json:"intentDetectionConfidence"`
	DiagnosticInfo            interface{} `json:"diagnosticInfo"`
}

QueryResult contains the result of the conversation query or event processing.

type Request

type Request struct {
	ResponseID                  string      `json:"responseId"`
	Session                     string      `json:"session"`
	QueryResult                 QueryResult `json:"queryResult"`
	OriginalDetectIntentRequest struct {
		Source  string `json:"source"`
		Version string `json:"version"`
		Payload struct {
			IsInSandbox bool `json:"isInSandbox"`
			Surface     struct {
				Capabilities []interface{} `json:"capabilities"`
			} `json:"surface"`
			Inputs []interface{} `json:"inputs"`
			User   struct {
				UserID   string `json:"userId"`
				Locale   string `json:"locale"`
				LastSeen string `json:"lastSeen"`
			} `json:"user"`
			Conversation      interface{}   `json:"conversation"`
			AvailableSurfaces []interface{} `json:"availableSurfaces"`
		} `json:"payload"`
	} `json:"originalDetectIntentRequest"`
}

Request contains all the inbound information from a Dialogflow fulfillment request. The QueryResult field contains most of the needed information. For more information about how to fill this struct, see the documentation at: https://dialogflow.com/docs/fulfillment/how-it-works.

func (*Request) GetParam

func (r *Request) GetParam(name string) (interface{}, error)

GetParam is a convenience method for getting a parameter from QueryResult.Parameters. If the parameter does not exist, an error will be returned.

func (*Request) GetStringParam

func (r *Request) GetStringParam(name string) (string, error)

GetStringParam is a convenience method for getting a parameter from QueryResult.Parameters. If the parameter does not exist or is not a string, an error will be returned.

type RichFulfillmentPayload

type RichFulfillmentPayload struct {
	ExpectUserResponse bool `json:"expectUserResponse"`
	RichResponse       struct {
		Items []interface{} `json:"items"`
	} `json:"richResponse"`
}

RichFulfillmentPayload can be used for rich responses to Google Actions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL