dialogflow

package module
v0.0.0-...-b3e19bd Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

dialogflow

dialogflow client library. This library supports api.ai webhook.

parse request from dialogflow

use json.Unmarshal()

func handler(w http.ResponseWriter, r *http.Request) {
        buf := new(bytes.Buffer)
        buf.ReadFrom(r.Body)
        var request dialogflow.Request
        err := json.Unmarshal(buf.Bytes(), &request)
        ...

build response for dialogflow

// w is http.ResponseWriter
resp = dialogflow.NewSSMLResponse(
    "speak response",
    "displayText response",
    true,
)    
data, _ := resp.ToJSON()
w.Write(data)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fulfillment

type Fulfillment struct {
	Speech   string    `json:speech`
	Messages []Message `json:messages`
}

type Input

type Input struct {
	Intent    string     `json:intent`
	RaqInputs []RawInput `json:"raw_inputs"`
}

type Message

type Message struct {
	Type   int    `json:type`
	Speech string `json:speech`
}

type MetaData

type MetaData struct {
	IntentID   string `json:intentId`
	IntentName string `json:intentName`
}

type OriginalRequest

type OriginalRequest struct {
	Source string `json:source`
	Data   struct {
		Inputs []Input `json:inputs`
		User   User    `json:user`
	} `json:data`
}

type RawInput

type RawInput struct {
	Query string `json:query`
	Type  int    `json:"input_type"`
}

type Request

type Request struct {
	OriginalRequest OriginalRequest `json:originalRequest`
	ID              string          `json:id`
	Result          Result          `json:result`
	SessionID       string          `json:sessionId`
	Status          Status          `json:status`
}

type Response

type Response struct {
	Speech             string
	DisplayText        string
	ExpectUserResponse bool
	IsSSML             bool
}

func NewSSMLResponse

func NewSSMLResponse(ssml, display string, expectedUserResponse bool) Response

func (Response) ToJSON

func (r Response) ToJSON() ([]byte, error)

type Result

type Result struct {
	Source        string                 `json:source`
	ResolvedQuery string                 `json:resolvedQuery`
	Fulfillment   Fulfillment            `json:fulfillment`
	MetaData      MetaData               `json:metadata`
	Params        map[string]interface{} `json:"parameters"`
}

type Status

type Status struct {
	Code      int    `json:code`
	ErrorType string `json:errorType`
}

type User

type User struct {
	ID          string `json:"userId"`
	Locale      string `json:locale`
	AccessToken string `json:"accessToken"`
}

Jump to

Keyboard shortcuts

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