dpl

package
v0.0.0-...-716b1b3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	dueros.Bot
	UserEvent *event.UserEvent // 设备端通过 SendEvent 指令上报
	// contains filtered or unexported fields
}

技能基础类

func NewBot

func NewBot() *Bot

创建常驻bot类,可维持在内存状态中, addhandler 和 addEventer事件可以缩减为一次

func (*Bot) Handler

func (bot *Bot) Handler(request string) string

根据每个请求分别处理

type Document

type Document struct {
	Error           error                  `json:"-"`
	Type            string                 `json:"type"`                      // type: 指令类型,即"DPL"
	Version         string                 `json:"version"`                   // version: 定版本信息,目前推荐使用 2.0 版本
	Duration        int                    `json:"duration,omitempty"`        // duration: 用户指定模版无交互超时退出时间,单位毫秒ms, 取值需要大于0, 默认 30 秒
	OnStackDuration int                    `json:"onStackDuration,omitempty"` // onStackDuration: 当模版被压栈时的超时退出时间,单位毫秒ms, 默认 10 分钟
	PageName        string                 `json:"pageName,omitempty"`        // pageName: 全局定义的 pageName 参数,用来给 bot 端定义该页面的名称
	RenderConfig    interface{}            `json:"renderConfig,omitempty"`    // renderConfig: 页面渲染配置信息
	Events          map[string]interface{} `json:"events,omitempty"`          // events: 基于模板的全局 events 描述
	Resources       []interface{}          `json:"resources,omitempty"`       // resources: 用户自定义 style 的属性常量, 可以在 styles 属性中引用属性常量, 引用方式@
	Styles          map[string]interface{} `json:"styles,omitempty"`          // styles: 用户自定义 styles 样式, 可以在 COMPONENT 中引入对应的自定义 styles 名称
	DataSource      map[string]interface{} `json:"dataSource,omitempty"`      // dataSource: 用户自定义的数据部分, 可以在 COMPONENT 中引用 dataSource, 引用方式${}
	Layouts         map[string]Template    `json:"layouts,omitempty"`         // layouts: 用户自定义样式, 可以在 mainTemplate 中的 items 中引用自定义的 layout
	Stylesheet      interface{}            `json:"stylesheet,omitempty"`      // stylesheet: 通过 class 与 mediaQuery 的组合使用,更好的支持基于不同尺寸的设备适配
	Abilities       []interface{}          `json:"abilities,omitempty"`       // abilities: 模板接入的能力,数组: ability[]
	MainTemplate    *Template              `json:"mainTemplate"`              // mainTemplate: 基于嵌套组件组合的模板解析入口
}

document: 包含渲染环境、指定渲染页面的 document 协议内容数据对象

DPL document 是一个基于 bot 协议的描述、有着完整结构定义的 JSON 对象数据, 它定义了协议中对应于在页面中需要渲染展现的动态渲染模板部分 (包括在页面上渲染展示的所有组件、数据内容和布局结构)以及设定页面模板的默认配置和交互能力 (无交互超时退出时间、预设事件绑定指令执行机制等)。

该字段的解析都必须通过 bot 端下发的方式来执行,目前对于 DPL document 字段属性有两种应用场景:

DPL.RenderDocument 指令下发必须包含该字段;

DPL.ExecuteCommands 指令中包含 document 更新的指令类型必须包含该字段;

func NewDocument

func NewDocument(path ...string) *Document

func (*Document) AddComponent

func (doc *Document) AddComponent(components ...interface{}) *Document

func (*Document) AddComponentFromFile

func (doc *Document) AddComponentFromFile(path ...string) *Document

Add Component from json file.

func (*Document) AddParameter

func (doc *Document) AddParameter(parameters ...string) *Document

func (*Document) GetDocumentFromFile

func (doc *Document) GetDocumentFromFile(path ...string) *Document

Load Document from json file.

func (*Document) GetLastError

func (doc *Document) GetLastError() error

func (*Document) GetRenderDocument

func (doc *Document) GetRenderDocument() *RenderDocument

DPL 渲染指令结构(RenderDocument)

func (*Document) Marshal

func (doc *Document) Marshal() ([]byte, error)

Marshal Document to []byte

func (*Document) SetAbilities

func (doc *Document) SetAbilities(abilities []interface{}) *Document

abilities: 模板接入的能力,数组: ability[]

ability: 能力组件

Gesture: 支持在端上打开手势识别能力,可以识别 手掌,Ok类型手势,触发对应的事件:

	onPalm: 识别手掌手势成功,触发事件

	onOk: 识别Ok手势成功,触发事件

Form: 支持表单能力,可以声明多个表单项组件(Input)属于该表单,然后基于调用表单方法与事件统一、部分操控表单项

	onReady: 表单中所有表单项满足校验条件,进入可被提交状态

	onPrepare: 表单中存在部分表单项未满足校验条件,不可被提交

	onSubmit: 表单成功提交

	onValidateFail: 表单提交验证失败

func (*Document) SetDataSource

func (doc *Document) SetDataSource(dataSource map[string]interface{}) *Document

dataSource: 用户自定义的数据部分, 可以在 COMPONENT 中引用 dataSource, 引用方式${}

func (*Document) SetDuration

func (doc *Document) SetDuration(duration int) *Document

duration: 用户指定模版无交互超时退出时间,单位毫秒ms, 取值需要大于0, 默认 30 秒

func (*Document) SetEvents

func (doc *Document) SetEvents(events map[string]interface{}) *Document

events: 基于模板的全局 events 描述

func (*Document) SetLayouts

func (doc *Document) SetLayouts(layouts map[string]Template) *Document

layouts: 用户自定义样式, 可以在 mainTemplate 中的 items 中引用自定义的 layout

func (*Document) SetMainTemplate

func (doc *Document) SetMainTemplate(parameters []string, components ...interface{}) *Document

mainTemplate: 基于嵌套组件组合的模板解析入口

parameters: 作为指定 dataSource 数据源的引用别名

items: 模版的嵌套子组件数组,基于嵌套的结构和组件的类型提供了整个模板页面的渲染展现和布局、功能

func (*Document) SetOnStackDuration

func (doc *Document) SetOnStackDuration(onStackDuration int) *Document

onStackDuration: 当模版被压栈时的超时退出时间,单位毫秒ms, 默认 10 分钟

func (*Document) SetPageName

func (doc *Document) SetPageName(pageName string) *Document

pageName: 全局定义的 pageName 参数,用来给 bot 端定义该页面的名称

func (*Document) SetRenderConfig

func (doc *Document) SetRenderConfig(renderConfig interface{}) *Document

renderConfig: 页面渲染配置信息

func (*Document) SetResources

func (doc *Document) SetResources(resources []interface{}) *Document

resources: 用户自定义 style 的属性常量, 可以在 styles 属性中引用属性常量, 引用方式@

- 对应的属性只能是 description、colors、dimensions

func (*Document) SetStyles

func (doc *Document) SetStyles(styles map[string]interface{}) *Document

styles: 用户自定义 styles 样式, 可以在 COMPONENT 中引入对应的自定义 styles 名称

func (*Document) SetStylesheet

func (doc *Document) SetStylesheet(stylesheet interface{}) *Document

stylesheet: 通过 class 与 mediaQuery 的组合使用,更好的支持基于不同尺寸的设备适配

[配置形式一]

'classNameString'
样式聚合类名

{'styleNameString': 'styleProp'}
样式属性对象

[配置形式二]

mediaQuery
设备类型(X5)或设备条件判断属性

classList
样式聚合类列表

'classNameString'
样式聚合类名

{'styleNameString': 'styleProp'}
样式属性对象

func (*Document) Unmarshal

func (doc *Document) Unmarshal(data []byte) error

Unmarshal Document from json []byte.

type ExecuteCommands

type ExecuteCommands struct {
	directive.BaseDirective                    // type: 指令类型,此处应为:DPL.ExecuteCommands
	Token                   string             `json:"token"`    // token: 指令 token 值需要 match 匹配基于用户请求时的页面状态 token
	Commands                []*command.Command `json:"commands"` // 指定执行的 commands 数组
}

func NewExecuteCommands

func NewExecuteCommands(cmds ...*command.Command) *ExecuteCommands

func (*ExecuteCommands) SetCommands

func (e *ExecuteCommands) SetCommands(cmds ...*command.Command)

func (*ExecuteCommands) SetToken

func (e *ExecuteCommands) SetToken(token string)

type RenderConfig

type RenderConfig struct {
	Viewport          *screen.Viewport `json:"viewport"`          // viewport: 页面可视区域大小
	GlobalVslDisabled bool             `json:"globalVslDisabled"` // globalVslDisabled:
}

func NewRenderConfig

func NewRenderConfig(width, height string, globalVslDisabled bool) *RenderConfig

type RenderDocument

type RenderDocument struct {
	directive.BaseDirective           // type: 目前仅提供 DPL.RenderDocument 作为页面的渲染模板指令
	Token                   string    `json:"token"`    // token: 作为当前页面渲染指令在页面渲染后的唯一标识
	Document                *Document `json:"document"` // document: 包含渲染环境、指定渲染页面的 document 协议内容数据对象
}

DPL 渲染指令结构(RenderDocument)

当一个技能服务收到来自设备端的请求时,它可以以一个 DPL.RenderDocument 页面渲染指令作为响应, 在 RenderDocument 指令中包含了一个 document 字段内容作为页面渲染的模板描述, 并指定一个唯一的 token 字段作为页面的标识下发该指令到支持 DPL 渲染的设备端上来渲染页面模板。

用于渲染 DPL 模板指令,通过下发该指令在设备端上渲染一个 DPL 页面

func NewRenderDocument

func NewRenderDocument(doc *Document) *RenderDocument

func (*RenderDocument) Marshal

func (r *RenderDocument) Marshal() ([]byte, error)

Marshal RenderDocument to []byte

func (*RenderDocument) SetDocument

func (r *RenderDocument) SetDocument(doc *Document)

func (*RenderDocument) Unmarshal

func (r *RenderDocument) Unmarshal(data []byte) error

Unmarshal RenderDocument from json []byte.

type Resource

type Resource struct {
	Description string            `json:"description"` // description: 对属性常量的描述,解析的时候会被忽略
	Colors      map[string]string `json:"colors"`      // colors: 定义颜色的属性常量,只能是颜色值
	Dimensions  map[string]string `json:"dimensions"`  // dimensions: 定义其他属性值, 如宽高、左右间距
}

type Template

type Template struct {
	Parameters []string      `json:"parameters"` // parameters: 指定 dataSource 的引用别名
	Items      []interface{} `json:"items"`      // items: 模版的子组件数组
}

基于嵌套组件组合的模板解析入口

parameters 作为指定 dataSource 数据源的引用别名

items 模版的嵌套子组件数组,基于嵌套的结构和组件的类型提供了整个模板页面的渲染展现和布局、功能

func NewTemplate

func NewTemplate(parameters []string, components ...interface{}) *Template

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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