speech

package
v0.0.0-...-a59aedb Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Template

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

Template represents a single type of speech response that you can return from your intent handler. The idea is that if your intent can say one of 5 possible "things" based on the input data then you should create 5 of these so that you can decide which one to evaluate. A golexa template also supports defining translations for other languages based on the incoming request's language.

func NewTemplate

func NewTemplate(englishSpeech string, options ...TemplateOption) Template

NewTemplate creates a brand new template for one of your possible responses. It includes an English (US) translation by default, but you can use the `WithTranslation` option to define translations for other languages. Since the translations use standard Go templates, you can define custom functions that should be available in this template using `WithFunc`.

func (Template) Eval

func (t Template) Eval(ctx TemplateContext) (string, error)

Eval processes the parsed template using the given contextual data.

type TemplateContext

type TemplateContext struct {
	Language language.Tag
	Now      time.Time
	Value    interface{}
}

TemplateContext represents the single piece of 'data' that you pass to a template when evaluating it. This gives your template access to some higher level data like the current timestamp and request as well as any data you generated when handling the intent that has an effect on the speech response.

type TemplateOption

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

TemplateOption should not be used directly. Use WithFunc or WithTranslation to provide the template option of your choice.

func WithFunc

func WithFunc(name string, function interface{}) TemplateOption

WithFunc adds a named function that will be available when parsing/evaluating responses.

func WithTranslation

func WithTranslation(lang language.Tag, localizedSpeech string) TemplateOption

WithTranslation defines a version of this response that is localized for the given language. This can be a plain text template (parsed using standard Go templates) or an SSML template.

Jump to

Keyboard shortcuts

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