dialogflow-go-webhook: github.com/leboncoin/dialogflow-go-webhook Index | Examples | Files

package dialogflow

import "github.com/leboncoin/dialogflow-go-webhook"

Index

Examples

Package Files

context.go dialogflow.go fulfillment.go location.go platform.go types.go

type BasicCard Uses

type BasicCard struct {
    Title         string       `json:"title,omitempty"`         // Optional. The title of the card.
    Subtitle      string       `json:"subtitle,omitempty"`      // Optional. The subtitle of the card.
    FormattedText string       `json:"formattedText,omitempty"` // Required, unless image is present. The body text of the card.
    Image         *Image       `json:"image,omitempty"`         // Optional. The image for the card.
    Buttons       []CardButton `json:"buttons,omitempty"`       // Optional. The collection of card buttons.
}

BasicCard is a simple card. Simply adds an extra Image field

func (BasicCard) GetKey Uses

func (bc BasicCard) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the BasicCard type

type Button Uses

type Button struct {
    Text     string `json:"text,omitempty"`     // Optional. The text to show on the button.
    PostBack string `json:"postback,omitempty"` // Optional. The text to send back to the Dialogflow API or a URI to open.
}

Button contains information about a button

type Card Uses

type Card struct {
    Title    string   `json:"title,omitempty"`    // Optional. The title of the card.
    Subtitle string   `json:"subtitle,omitempty"` // Optional. The subtitle of the card.
    Buttons  []Button `json:"buttons,omitempty"`  // Optional. The collection of card buttons.
    Image
}

Card is a simple card. Different type than the BasicCard, the buttons change. This card has buttons with postback field, whereas BasicCard has cards with OpenURI action

func (Card) GetKey Uses

func (c Card) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the Card type

type CardButton Uses

type CardButton struct {
    Title         string         `json:"title,omitempty"`         // Optional. The text to show on the button.
    OpenURIAction *OpenURIAction `json:"openUriAction,omitempty"` // Required. Action to take when a user taps on the button.
}

CardButton is a he button object that appears at the bottom of a card

type CarouselSelect Uses

type CarouselSelect struct {
    Items []Item `json:"items,omitempty"` // Required. Carousel items.
}

CarouselSelect shows a carousel to the user

func (CarouselSelect) GetKey Uses

func (c CarouselSelect) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the CarouselSelect type

type Context Uses

type Context struct {
    Name          string          `json:"name,omitempty"`
    LifespanCount int             `json:"lifespanCount,omitempty"`
    Parameters    json.RawMessage `json:"parameters,omitempty"`
}

Context is a context contained in a query

type Contexts Uses

type Contexts []*Context

Contexts is a slice of pointer to Context

type FollowupEventInput Uses

type FollowupEventInput struct {
    Name         string      `json:"name"`
    LanguageCode string      `json:"languageCode,omitempty"`
    Parameters   interface{} `json:"parameters,omitempty"`
}

FollowupEventInput Optional. Makes the platform immediately invoke another sessions.detectIntent call internally with the specified event as input. https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/projects.agent.sessions/detectIntent#EventInput

type Fulfillment Uses

type Fulfillment struct {
    FulfillmentText     string             `json:"fulfillmentText,omitempty"`
    FulfillmentMessages Messages           `json:"fulfillmentMessages,omitempty"`
    Source              string             `json:"source,omitempty"`
    Payload             interface{}        `json:"payload,omitempty"`
    OutputContexts      Contexts           `json:"outputContexts,omitempty"`
    FollowupEventInput  FollowupEventInput `json:"followupEventInput,omitempty"`
}

Fulfillment is the response sent back to dialogflow in case of a successful webhook call

type Image Uses

type Image struct {
    ImageURI string `json:"imageUri,omitempty"` // Optional. The public URI to an image file.
}

Image is a simple type of message sent back to dialogflow

func (Image) GetKey Uses

func (i Image) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the Image type

type Intent Uses

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

Intent describes the matched intent

type Item Uses

type Item struct {
    Info        SelectItemInfo `json:"info,omitempty"`        // Required. Additional information about this option
    Title       string         `json:"title,omitempty"`       // Required. The title of the list item
    Description string         `json:"description,omitempty"` // Optional. The main text describing the item
    Image       *Image         `json:"image,omitempty"`       // Optional. The image to display.
}

Item is a single item present in a list

type LinkOutSuggestion Uses

type LinkOutSuggestion struct {
    DestinationName string `json:"suggestionName,omitempty"` // Required. The name of the app or site this chip is linking to.
    URI             string `json:"uri,omitempty"`            // Required. The URI of the app or site to open when the user taps the suggestion chip.
}

LinkOutSuggestion can be used to suggest the user to click on a link that will get him out of the app

func (LinkOutSuggestion) GetKey Uses

func (l LinkOutSuggestion) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the LinkOutSuggestion type

type ListSelect Uses

type ListSelect struct {
    Title string `json:"title,omitempty"` // Required. The overall title of the list.
    Items []Item `json:"items,omitempty"` // Required. List items.
}

ListSelect can be used to show a list to the user

func (ListSelect) GetKey Uses

func (l ListSelect) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the ListSelect type

type Location Uses

type Location struct {
    Simple               string
    AdminArea            string          `json:"admin-area,omitempty"`
    AdminAreaOriginal    string          `json:"admin-area.original,omitempty"`
    AdminAreaObject      json.RawMessage `json:"admin-area.object,omitempty"`
    SubAdminArea         string          `json:"subadmin-area,omitempty"`
    SubAdminAreaOriginal string          `json:"subadmin-area.original,omitempty"`
}

Location is a location object sent back by DialogFlow

func (*Location) UnmarshalJSON Uses

func (l *Location) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaler interface for JSON parsing This function will try to unmarshal the incoming data to either a full Location object, or a simple string.

type Message Uses

type Message struct {
    Platform
    RichMessage RichMessage
}

Message is a struct holding a platform and a RichMessage. Used in the FulfillmentMessages of the response sent back to dialogflow

func ForGoogle Uses

func ForGoogle(r RichMessage) Message

ForGoogle takes a rich message wraps it in a message with the appropriate platform set

Code:

output := "Hello World !"
fulfillment := Fulfillment{
    FulfillmentMessages: Messages{
        ForGoogle(SingleSimpleResponse(output, output)),
    },
}
fmt.Println(fulfillment)

func (*Message) MarshalJSON Uses

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface for the JSON type. Custom marshalling is necessary since there can only be one rich message per Message and the key associated to each type is dynamic

type Messages Uses

type Messages []Message

Messages is a simple slice of Message

type OpenURIAction Uses

type OpenURIAction struct {
    URI string `json:"uri,omitempty"` // Required. The HTTP or HTTPS scheme URI.
}

OpenURIAction simply defines the URI associated with a button

type PayloadWrapper Uses

type PayloadWrapper struct {
    Payload interface{}
}

PayloadWrapper acts as a wrapper for the payload type

func (PayloadWrapper) GetKey Uses

func (p PayloadWrapper) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated to the Payload type

func (PayloadWrapper) MarshalJSON Uses

func (p PayloadWrapper) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface and will return the marshalled payload, ignoring the initial level

type Platform Uses

type Platform string

Platform is a simple type intended to be used with responses

const (
    Unspecified     Platform = "PLATFORM_UNSPECIFIED"
    Facebook        Platform = "FACEBOOK"
    Slack           Platform = "SLACK"
    Telegram        Platform = "TELEGRAM"
    Kik             Platform = "KIK"
    Skype           Platform = "SKYPE"
    Line            Platform = "LINE"
    Viber           Platform = "VIBER"
    ActionsOnGoogle Platform = "ACTIONS_ON_GOOGLE"
)

Platform constants, used in the webhook responses

type QueryResult Uses

type QueryResult struct {
    QueryText                 string          `json:"queryText,omitempty"`
    Action                    string          `json:"action,omitempty"`
    LanguageCode              string          `json:"languageCode,omitempty"`
    AllRequiredParamsPresent  bool            `json:"allRequiredParamsPresent,omitempty"`
    IntentDetectionConfidence float64         `json:"intentDetectionConfidence,omitempty"`
    Parameters                json.RawMessage `json:"parameters,omitempty"`
    OutputContexts            []*Context      `json:"outputContexts,omitempty"`
    Intent                    Intent          `json:"intent,omitempty"`
}

QueryResult is the dataset sent back by DialogFlow

type QuickReplies Uses

type QuickReplies struct {
    Title   string   `json:"title,omitempty"`        // Optional. The title of the collection of quick replies.
    Replies []string `json:"quickReplies,omitempty"` // Optional. The collection of quick replies.
}

QuickReplies is a structured response sent back to dialogflow

func (QuickReplies) GetKey Uses

func (qr QuickReplies) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the QuickReplies type

type Request Uses

type Request struct {
    Session                     string          `json:"session,omitempty"`
    ResponseID                  string          `json:"responseId,omitempty"`
    QueryResult                 QueryResult     `json:"queryResult,omitempty"`
    OriginalDetectIntentRequest json.RawMessage `json:"originalDetectIntentRequest,omitempty"`
}

Request is the top-level struct holding all the information Basically links a response ID with a query result.

func (*Request) GetContext Uses

func (rw *Request) GetContext(ctx string, i interface{}) error

GetContext allows to search in the output contexts of the query

func (*Request) GetParams Uses

func (rw *Request) GetParams(i interface{}) error

GetParams simply unmarshals the parameters to the given struct and returns an error if it's not possible

func (*Request) NewContext Uses

func (rw *Request) NewContext(name string, lifespan int, params interface{}) (*Context, error)

NewContext is a helper function to create a new named context with params name and a lifespan

type RichMessage Uses

type RichMessage interface {
    GetKey() string
}

RichMessage is an interface used in the Message type. It is used to send back payloads to dialogflow

type SelectItemInfo Uses

type SelectItemInfo struct {
    Key      string   `json:"key,omitempty"`      //  Required. A unique key that will be sent back to the agent if this response is given.
    Synonyms []string `json:"synonyms,omitempty"` //  Optional. A list of synonyms that can also be used to trigger this item in dialog.
}

SelectItemInfo is a struct holding data about a specific item

type SimpleResponse Uses

type SimpleResponse struct {
    TextToSpeech string `json:"textToSpeech,omitempty"` // One of textToSpeech or ssml must be provided. The plain text of the speech output. Mutually exclusive with ssml.
    DisplayText  string `json:"displayText,omitempty"`  // Optional. The text to display.
    SSML         string `json:"ssml,omitempty"`         // One of textToSpeech or ssml must be provided. Structured spoken response to the user in the SSML format. Mutually exclusive with textToSpeech.
}

SimpleResponse is a simple response sent back to dialogflow. Composed of two types, TextToSpeech will be converted to speech and DisplayText will be displayed if the surface allows to display stuff

type SimpleResponsesWrapper Uses

type SimpleResponsesWrapper struct {
    SimpleResponses []SimpleResponse `json:"simpleResponses,omitempty"` // Required. The list of simple responses.
}

SimpleResponsesWrapper wraps SimpleResponses

func SingleSimpleResponse Uses

func SingleSimpleResponse(display, speech string) SimpleResponsesWrapper

SingleSimpleResponse is a wrapper to create one simple response to display and play to the user

func (SimpleResponsesWrapper) GetKey Uses

func (s SimpleResponsesWrapper) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the SimpleResponsesWrapper type

type Suggestion Uses

type Suggestion struct {
    Title string `json:"title,omitempty"` // Required. The text shown the in the suggestion chip.
}

Suggestion is a simple suggestion

type Suggestions Uses

type Suggestions struct {
    Suggestions []Suggestion `json:"suggestions,omitempty"` // Required. The list of suggested replies.
}

Suggestions is a rich message that suggests the user quick replies

func (Suggestions) GetKey Uses

func (s Suggestions) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated to the Suggestions type

type Text Uses

type Text struct {
    Text []string `json:"text,omitempty"` // Optional. The collection of the agent's responses.
}

Text is a simple wrapper around a list of string

func (Text) GetKey Uses

func (t Text) GetKey() string

GetKey implements the RichMessage interface and returns the JSON key associated with the Text type

Package dialogflow imports 5 packages (graph). Updated 2018-09-25. Refresh now. Tools for package owners.