fulfillment

package
v0.0.0-...-e304f20 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

fulfillment

Example Usage

package main

import (
    "fmt"

    "github.com/kelseyhightower/dialogflow/fulfillment"
    "google.golang.org/api/dialogflow/v2"
)

func main() {
    fs := fulfillment.NewServer()
    fs.Actions.Set("helloworld", helloworld)
    fs.DisableBasicAuth = true
    fs.ListenAndServe()
}

func helloworld(q *dialogflow.GoogleCloudDialogflowV2WebhookRequest) (*dialogflow.GoogleCloudDialogflowV2WebhookResponse, error) {
    response := &dialogflow.GoogleCloudDialogflowV2WebhookResponse{
        FulfillmentText: "Hello World!",
    }
    return response, nil
}

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

Examples

Constants

This section is empty.

Variables

View Source
var DefaultCacheDirectory = "/var/lib/dialogflow/fulfillment"

DefaultCacheDirectory is the default directory to use when caching certificates from Let's Encrypt.

View Source
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.

View Source
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

func Handler

func Handler(actions Actions) http.Handler

Handler returns a handler that processes Dialogflow fulfillment requests using the given actions.

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 NewActions

func NewActions() Actions

NewActions returns a new, empty Actions map.

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 NewServer

func NewServer() *Server

NewServer initializes and returns a new Server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

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

func (s *Server) ListenAndServeTLS(certFile, keyFile string) error

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

func (s *Server) ListenAndServeTLSUntilSignal(certFile, keyFile string, sig ...os.Signal)

ListenAndServeTLSUntilSignal invokes ListenAndServe and blocks until one of the given OS signals are called.

func (*Server) ListenAndServeUntilSignal

func (s *Server) ListenAndServeUntilSignal(sig ...os.Signal)

ListenAndServeUntilSignal invokes ListenAndServe and blocks until one of the given OS signals are called.

func (*Server) SetStatus

func (s *Server) SetStatus(status int)

SetStatus sets the status of the fulfillment server.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown gracefully shuts down the fulfillment server.

Shutdown works by calling Shutdown on the fulfillment and acme HTTP challenge servers managed by the Server.

func (*Server) Status

func (s *Server) Status() int

Status returns the status of the fulfillment server.

Jump to

Keyboard shortcuts

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