Documentation ¶
Overview ¶
Package fulfillment provides a HTTP handler for processing Dialogflow fulfillment requests.
This package also provides a server implementation for building Dialogflow fulfillment webhooks.
Example ¶
fs := fulfillment.NewServer() fs.DisableBasicAuth = true fs.Actions.Set("helloworld", func(q *dialogflow.GoogleCloudDialogflowV2WebhookRequest) (*dialogflow.GoogleCloudDialogflowV2WebhookResponse, error) { response := &dialogflow.GoogleCloudDialogflowV2WebhookResponse{ FulfillmentText: "Hello World!", } return response, nil }) fs.ListenAndServe()
Output:
Index ¶
- Variables
- func Handler(actions Actions) http.Handler
- type ActionFunc
- type Actions
- type Server
- func (s *Server) ListenAndServe() error
- func (s *Server) ListenAndServeTLS(certFile, keyFile string) error
- func (s *Server) ListenAndServeTLSUntilSignal(certFile, keyFile string, sig ...os.Signal)
- func (s *Server) ListenAndServeUntilSignal(sig ...os.Signal)
- func (s *Server) SetStatus(status int)
- func (s *Server) Shutdown()
- func (s *Server) Status() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultCacheDirectory = "/var/lib/dialogflow/fulfillment"
DefaultCacheDirectory is the default directory to use when caching certificates from Let's Encrypt.
var ErrEmptyHashedPassword = errors.New("dialogflow/fulfillment: basic auth hashed password is empty")
ErrEmptyHashedPassword is returned from ListenAndServe and ListenAndServeTLS when basic authentication is required and the hashed password is empty.
var ErrEmptyUsername = errors.New("dialogflow/fulfillment: basic auth username is empty")
ErrEmptyUsername is returned from ListenAndServe and ListenAndServeTLS when basic authentication is required and the username is empty.
Functions ¶
Types ¶
type ActionFunc ¶
type ActionFunc func(*dialogflow.GoogleCloudDialogflowV2WebhookRequest) (*dialogflow.GoogleCloudDialogflowV2WebhookResponse, error)
An ActionFunc processes an dialogflow.WebhookRequest and returns a dialogflow.WebhookResponse.
type Actions ¶
type Actions map[string]ActionFunc
An Actions represents the supported actions of a fulfillment server.
func (Actions) Set ¶
func (a Actions) Set(name string, fn ActionFunc)
Set sets the ActionFunc entry associated with name. It replaces any existing value associated with name.
type Server ¶
type Server struct { // ACMEHTTPChallengeServer holds the ACME HTTP challenge server. ACMEHTTPChallengeServer *http.Server // Actions used by fulfillment handler. Actions Actions // AutocertCache specifies an optional autocert.Cache implementation used // to store and retrieve previously obtained Let's Encrypt certificates as // opaque data. // // If AutocertCache is nil, autocert.DirCache will be used. // If AutocertCache is not nil, Let's Encrypt is not enabled automatically. AutocertCache autocert.Cache // BasicAuthUsername specifies an optional basic authentication username used // to authenticate fulfillment requests. // // If BasicAuthUsername is blank, DefaultBasicAuthUsername will be used. BasicAuthUsername string // BasicAuthHashedPassword specifies an optional basic authentication hashed // password used to authenticate HTTPS requests. // // BasicAuthHashedPassword must be hashed using bcrypt. // // If BasicAuthHashedPassword is not blank, basic authentication is enabled // for all fulfillment requests. BasicAuthHashedPassword string // CacheDirectory specifies an optional directory to use when caching // certificates from Let's Encrypt. If CacheDirectory is not blank, // Let's Encrypt is not enabled automatically. CacheDirectory string // Domain specifies an optional fully qualifed domain used when generating // certificates from Let's Encrypt. If Domain is not blank, Let's Encrypt // is enabled automatically. Domain string // DisableBasicAuth, if true, basic authentication is disabled for fulfillment // requests. // // If DisableBasicAuth is false, BasicAuthUsername and BasicAuthHashedPassword // must be set and non-empty. Defaults to false. DisableBasicAuth bool *http.Server // contains filtered or unexported fields }
A Server defines parameters for running a fulfillment server.
A Server must be initialized before use.
func (*Server) ListenAndServe ¶
ListenAndServe listens on TCP address s.Addr to handle Dialogflow fulfillment requests.
If s.Addr is blank, "0.0.0.0:80" is used.
ListenAndServe always returns a non-nil error.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on TCP address s.Addr to handle Dialogflow fulfillment requests.
If s.Addr is blank, "0.0.0.0:443" is used. If s.ACMEHTTPChallengeServer.Addr is blank, "0.0.0.0:80" is used.
If s.Domain is not blank, Let's Encrypt is enabled automatically for the domain. Use of this function implies acceptance of the LetsEncrypt Terms of Service.
Let's Encrypt certificates are cached using an implementation of autocert.Cache specified by s.AutocertCache. If s.AutocertCache is nil, an autocert.Cache will be created based on s.CacheDirectory or s.Bucket. If s.CacheDirectory and s.Bucket are blank, an autocert.Cache will be created based on DefaultCacheDirectory.
ListenAndServeTLS always returns a non-nil error.
func (*Server) ListenAndServeTLSUntilSignal ¶
ListenAndServeTLSUntilSignal invokes ListenAndServe and blocks until one of the given OS signals are called.
func (*Server) ListenAndServeUntilSignal ¶
ListenAndServeUntilSignal invokes ListenAndServe and blocks until one of the given OS signals are called.