apiai

package module
v0.2.4-beta Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: MIT Imports: 10 Imported by: 0

README

Go SDK for api.ai

Go Report Card GoDoc Build Status codecov

This library allows you to integrate Api.ai natural language processing service with your Go application. For more information see the docs.

We encourage you to follow this official guide to get started in 5 steps before proceeding.

Installation

go get github.com/marcossegovia/apiai-go

Usage

import (
        "fmt"

        "github.com/marcossegovia/apiai-go"
)

func main() {
    client, err := apiai.NewClient(
        &apiai.ClientConfig{
            Token:      "YOUR-API-AI-TOKEN",
            SessionId:  "YOUR_USER_SESSION_ID",
            QueryLang:  "en",    //Default en
            SpeechLang: "en-US", //Default en-US
        },
    )
    if err != nil {
        fmt.Printf("%v", err)
    }
    
    qr, err := client.Query(apiai.Query{Query: []string{"My name is Marcos and I live in Barcelona"}})
    if err != nil {
        fmt.Printf("%v", err)
    }
    fmt.Printf("%v", qr.Result.Fulfillment.Speech)
}

Bugs & Issues

See CONTRIBUTING

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

type ApiClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conf *ClientConfig) (*ApiClient, error)

func (*ApiClient) AddEntries

func (c *ApiClient) AddEntries(idOrName string, entries []Entry) error

func (*ApiClient) CreateContext

func (c *ApiClient) CreateContext(context Context) error

func (*ApiClient) CreateEntity

func (c *ApiClient) CreateEntity(entity Entity) (*CreationResponse, error)

func (*ApiClient) CreateIntent

func (c *ApiClient) CreateIntent(intent Intent) (*CreationResponse, error)

func (*ApiClient) DeleteContext

func (c *ApiClient) DeleteContext(name string) error

func (*ApiClient) DeleteContexts

func (c *ApiClient) DeleteContexts() error

func (*ApiClient) DeleteEntity

func (c *ApiClient) DeleteEntity(idOrName string) error

func (*ApiClient) DeleteEntries

func (c *ApiClient) DeleteEntries(idOrName string, entries []string) error

func (*ApiClient) DeleteIntent

func (c *ApiClient) DeleteIntent(id string) error

func (*ApiClient) GetContext

func (c *ApiClient) GetContext(name string) (*Context, error)

func (*ApiClient) GetContexts

func (c *ApiClient) GetContexts() ([]Context, error)

func (*ApiClient) GetEntities

func (c *ApiClient) GetEntities() ([]EntityDescription, error)

func (*ApiClient) GetEntity

func (c *ApiClient) GetEntity(idOrName string) (*Entity, error)

func (*ApiClient) GetIntent

func (c *ApiClient) GetIntent(id string) (*Intent, error)

func (*ApiClient) GetIntents

func (c *ApiClient) GetIntents() ([]IntentDescription, error)

func (*ApiClient) Query

func (c *ApiClient) Query(q Query) (*QueryResponse, error)

func (*ApiClient) Tts

func (c *ApiClient) Tts(text string) (string, error)

func (*ApiClient) UpdateEntities

func (c *ApiClient) UpdateEntities(entities []Entity) error

func (*ApiClient) UpdateEntity

func (c *ApiClient) UpdateEntity(idOrName string, entity Entity) error

func (*ApiClient) UpdateEntries

func (c *ApiClient) UpdateEntries(idOrName string, entries []Entry) error

func (*ApiClient) UpdateIntent

func (c *ApiClient) UpdateIntent(id string, intent Intent) error

type CardButton

type CardButton struct {
	Text     string
	Postback string
}

type Client

type Client interface {
	Query(Query) (*QueryResponse, error)
	Tts(text string) (string, error)
	GetContext(name string) (*Context, error)
	CreateContext(context Context) error
	DeleteContext(name string) error
	GetContexts() ([]Context, error)
	DeleteContexts() error
	GetEntities() ([]EntityDescription, error)
	UpdateEntities(entities []Entity) error
	GetEntity(idOrName string) (*Entity, error)
	CreateEntity(entity Entity) (*CreationResponse, error)
	UpdateEntity(idOrName string, entity Entity) error
	DeleteEntity(idOrName string) error
	AddEntries(idOrName string, entries []Entry) error
	UpdateEntries(idOrName string, entries []Entry) error
	DeleteEntries(idOrName string, entries []string) error
	GetIntent(id string) (*Intent, error)
	CreateIntent(intent Intent) (*CreationResponse, error)
	UpdateIntent(id string, intent Intent) error
	DeleteIntent(id string) error
	GetIntents() ([]IntentDescription, error)
}

type ClientConfig

type ClientConfig struct {
	Token      string //a9a9a9a9a9a9aa9a9a9a9a9a9a9a9a9a
	SessionId  string
	Version    string //YYYYMMDD
	QueryLang  string
	SpeechLang string
}

type Context

type Context struct {
	Name     string            `json:"name"`
	Lifespan int               `json:"lifespan"`
	Params   map[string]string `json:"parameters"`
}

type CortanaCommand

type CortanaCommand struct {
	NavigateOrService string `json:"navigateOrService"`
	Target            string `json:"target"`
}

type CreationResponse

type CreationResponse struct {
	Id     string `json:"id"`
	Status Status `json:"status"`
}

type Data

type Data struct {
	Text        string `json:"text"`
	Meta        string `json:"meta"`
	Alias       string `json:"alias"`
	UserDefined bool   `json:"userDefined"`
}

type Entity

type Entity struct {
	Id                 string  `json:"id"`
	Name               string  `json:"name"`
	Entries            []Entry `json:"entries"`
	IsEnum             bool    `json:"isEnum"`
	AutomatedExpansion bool    `json:"automatedExpansion"`
}

type EntityDescription

type EntityDescription struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Count   int    `json:"count"`
	Preview string `json:"preview"`
}

type Entry

type Entry struct {
	Value    string   `json:"value"`
	Synonyms []string `json:"synonyms"`
}

type Event

type Event struct {
	Name string            `json:"name"`
	Data map[string]string `json:"data"`
}

type Fulfilment

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

type Intent

type Intent struct {
	Id                    string           `json:"id"`
	Name                  string           `json:"name"`
	Auto                  bool             `json:"auto"`
	Contexts              []string         `json:"contexts"`
	Templates             []string         `json:"templates"`
	UserSays              []UserSays       `json:"userSays"`
	Responses             []IntentResponse `json:"responses"`
	Priority              int              `json:"priority"`
	WebhookUsed           bool             `json:"webhookUsed"`
	WebhookForSlotFilling bool             `json:"webhookForSlotFilling"`
	FallbackIntent        bool             `json:"fallbackIntent"`
	CortanaCommand        CortanaCommand   `json:"cortanaCommand"`
	Events                []Event          `json:"events"`
}

type IntentDescription

type IntentDescription struct {
	Id             string            `json:"id"`
	Name           string            `json:"name"`
	ContextIn      []string          `json:"contextIn"`
	ContextOut     []Context         `json:"contextOut"`
	Actions        []string          `json:"actions"`
	Params         []IntentParameter `json:"parameters"`
	Priority       int               `json:"priority"`
	FallbackIntent bool              `json:"fallbackIntent"`
}

type IntentParameter

type IntentParameter struct {
	Name         string   `json:"name"`
	Value        string   `json:"value"`
	DefaultValue string   `json:"defaultValue"`
	Required     bool     `json:"required"`
	DataType     string   `json:"dataType"`
	Prompts      []string `json:"prompts"`
	IsList       bool     `json:"isList"`
}

type IntentResponse

type IntentResponse struct {
	Action           string            `json:"action"`
	ResetContexts    bool              `json:"resetContexts"`
	AffectedContexts []Context         `json:"affectedContexts"`
	Params           []IntentParameter `json:"parameters"`
	Messages         []Message         `json:"messages"`
}

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type Message

type Message struct {
	Type     int          `json:"type"`
	Speech   string       `json:"speech"`
	ImageUrl string       `json:"imageUrl"`
	Title    string       `json:"title"`
	Subtitle string       `json:"subtitle"`
	Buttons  []CardButton `json:"buttons"`
	Replies  []string     `json:"replies"`
	Payload  interface{}  `json:"payload"`
}

type Metadata

type Metadata struct {
	IntentId                  string `json:"intentId"`
	WebhookUsed               string `json:"webhookUsed"`
	WebhookForSlotFillingUsed string `json:"webhookForSlotFillingUsed"`
	IntentName                string `json:"intentName"`
}

type Platform

type Platform struct {
	Source string            `json:"source"`
	Data   map[string]string `json:"data"`
}

type Query

type Query struct {
	Query           []string            `json:"query"`
	Event           Event               `json:"event"`
	Version         string              `json:"-"`
	SessionId       string              `json:"sessionId"`
	Language        string              `json:"lang"`
	Contexts        []Context           `json:"contexts"`
	ResetContexts   bool                `json:"resetContexts"`
	Entities        []EntityDescription `json:"entities"`
	Timezone        string              `json:"timezone"`
	Location        Location            `json:"location"`
	OriginalRequest Platform            `json:"originalRequest"`
}

type QueryResponse

type QueryResponse struct {
	Id        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Language  string    `json:"lang"`
	Result    Result    `json:"result"`
	Status    Status    `json:"status"`
	SessionId string    `json:"sessionId"`
}

type Result

type Result struct {
	Source           string            `json:"source"`
	ResolvedQuery    string            `json:"resolvedQuery"`
	Action           string            `json:"action"`
	ActionIncomplete bool              `json:"actionIncomplete"`
	Params           map[string]string `json:"parameters"`
	Contexts         []Context         `json:"contexts"`
	Fulfillment      Fulfilment        `json:"fulfillment"`
	Score            float64           `json:"score"`
	Metadata         Metadata          `json:"metadata"`
}

type Status

type Status struct {
	Code         int    `json:"code"`
	ErrorType    string `json:"errorType"`
	ErrorId      string `json:"errorId"`
	ErrorDetails string `json:"errorDetails"`
}

type UserSays

type UserSays struct {
	Id         string `json:"id"`
	Data       []Data `json:"data"`
	IsTemplate bool   `json:"isTemplate"`
	Count      int    `json:"count"`
}

Jump to

Keyboard shortcuts

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