Skip to content

Latest commit

 

History

History
1160 lines (909 loc) · 45.3 KB

Bot.md

File metadata and controls

1160 lines (909 loc) · 45.3 KB

Bot

Bot基类. 请继承此类

Kind: global class

new Bot(postData)

构造函数,以及DuerOS请求bot的request为参数,request协议参考[http://TODO]

Param Type Description
postData Object DuerOS请求body

Example

const BaseBot = require('bot-sdk');
class MyBot extends BaseBot {
    constructor(postData) {
         super(postData);
         //...
    }
}

bot.addLaunchHandler(handler) ⇒ Bot

对SessionEnded添加处理函数

Kind: instance method of Bot
Returns: Bot - 返回自己
Access: public

Param Type Description
handler function 意图处理函数。返回值非null,将作为bot的response返回DuerOS 函数返回值参考Response.build() 的输入参数

Example

this.addLaunchHandler(()=>{
     // 进入bot,提示用户如何操作
});

bot.addSessionEndedHandler(handler) ⇒ Bot

对SessionEnded添加处理函数

Kind: instance method of Bot
Returns: Bot - 返回自己
Access: public

Param Type Description
handler function 意图处理函数。返回值非null,将作为bot的response返回DuerOS 函数返回值参考Response.build() 的输入参数

Example

this.addSessionEndedHandler(()=>{
    // todo some clear job
    // this.clearSession()
});

bot.addIntentHandler(intent, handler) ⇒ Bot

对一个intent添加处理函数

Kind: instance method of Bot
Returns: Bot - 返回自己
Access: public

Param Type Description
intent string 意图名:'intentName'
handler function 意图处理函数。返回值非null,将作为bot的response返回DuerOS 函数返回值参考Response.build() 的输入参数

Example

this.addIntentHandler('intentName', ()=>{
    //this.getSlot('slotName');
});

bot.addEventListener(event, handler) ⇒ Bot

对一个事件添加处理函数。比如设备端反馈的音频播放开始事件

Kind: instance method of Bot
Returns: Bot - 返回自己
Access: public

Param Type Description
event string 事件名
handler function 事件处理函数。返回值非null,将作为bot的response返回DuerOS 函数返回值参考Response.build() 的输入参数

Example

this.addEventListener('Audio', (event)=>{
    // event 为事件数据 
    // 具体数据结构参考[TODO]
});

bot.addDefaultEventListener(handler) ⇒ Bot

默认兜底事件的处理回调。

Kind: instance method of Bot
Returns: Bot - 返回自己
Access: public

Param Type Description
handler function 处理函数,传入参数为事件的request,返回值做完response给DuerOS

bot.initCertificate(headers, body) ⇒ Certificate

初始化认证校验

Kind: instance method of Bot
Returns: Certificate - Certificate实例
Access: public

Param Type Description
headers Object http请求的header
body string 请求体

Example

this.initCertificate(
     {signature: '###', signaturecerturl: ''},
     '{"version":""}'
 );

bot.getIntentName() ⇒ string | null

获取DuerOS请求中的意图名

Kind: instance method of Bot
Access: public

bot.getSessionAttribute(field, defaultValue) ⇒ Mixied

获取session的一个字段对应的值

Kind: instance method of Bot
Access: public

Param Type Default Description
field string null 字段名
defaultValue Mixed 默认值 当此字段没有值时,返回defaultValue

bot.setSessionAttribute(field, value, defaultValue) ⇒ null

设置session的一个字段的值

Kind: instance method of Bot
Access: public

Param Type Default Description
field string 字段名
value Mixed 字段对应的值
defaultValue Mixed 默认值 当value为空时,使用defaultValue

bot.clearSessionAttribute() ⇒ null

清空session的所有字段

Kind: instance method of Bot
Access: public

bot.getSlot(field, index) ⇒ string

根据槽位名获取槽位对应的值

Kind: instance method of Bot
Access: public

Param Type Default Description
field string 槽位名
index Integer 0 第几个intent,默认第一个

bot.setSlot(field, value, index) ⇒ null

设置槽位的值。如果该槽位不存在,新增一个槽位名,并设置对于的值

Kind: instance method of Bot
Access: public

Param Type Default Description
field string 槽位名
value string
index Integer 0 第几个intent,默认第一个

bot.waitAnswer() ⇒ null

设置多轮继续,等待用户回复

Kind: instance method of Bot
Access: public

bot.endSession()

设置多轮结束,此时bot结束多轮对话

Kind: instance method of Bot
Access: public

bot.setPrivateKey(filename) ⇒ Promise

设置私钥

Kind: instance method of Bot

Param Type Description
filename string 私钥路径

bot.setExpectSpeech(expectSpeech)

通过控制expectSpeech来控制麦克风开

Kind: instance method of Bot

Param Type Description
expectSpeech boolean 是否开启麦克风

bot.endDialog()

告诉DuerOS,需要结束对话

Kind: instance method of Bot

bot.isSupportDisplay() ⇒ boolean

检测Display的数据是否存在

Kind: instance method of Bot
Access: public

bot.isSupportAudioPlayer() ⇒ boolean

检测AudioPlayer对象是否存在

Kind: instance method of Bot
Access: public

bot.isSupportVideoPlayer() ⇒ boolean

检测VideoPlayer对象是否存在

Kind: instance method of Bot
Access: public

bot.run(build) ⇒ Promise

bot执行的入口

Kind: instance method of Bot
Access: public

Param Type Default Description
build boolean true 是否需要打包response,输出JSON String

bot.addExpectSlotResponse(slot)

技能所期待的用户回复,技能将该信息反馈给DuerOS,有助于DuerOS在语音识别以及识别纠错时向该信息提权

Kind: instance method of Bot

Param Type Description
slot string 槽位类型回复表达的槽位名称。

bot.getApiAccessToken() ⇒ string

获取apiAccessToken

Kind: instance method of Bot

bot.getApiEndPoint() ⇒ string

获取apiEndPoint

Kind: instance method of Bot

bot.getUserProfile() ⇒ Promise

获取用户百度账号信息

Kind: instance method of Bot

bot.getRecordSpeech(audioToken) ⇒ Promise

获取用户录音数据

Kind: instance method of Bot

Param Type Description
audioToken string RecordSpeechFinished事件中的audioToken

bot.getDeviceLocation() ⇒ Promise

获取用户地理位置信息

Kind: instance method of Bot

bot.callSmarthomePrinter(data) ⇒ Promise

调用智能家居打印机服务

Kind: instance method of Bot

Param Type
data object

bot.sendMateappNotification(data) ⇒ Promise

小度音箱app通知接口

Kind: instance method of Bot

Param Type Description
data Object 参数对象

Bot.Card : object

Bot可以返回的卡片

Kind: static namespace of Bot

Card.TextCard

Kind: static property of Card
Access: public
See: TextCard

Card.ImageCard

Kind: static property of Card
Access: public
See: ImageCard

Card.StandardCard

Kind: static property of Card
Access: public
See: StandardCard

Card.ListCard

Kind: static property of Card
Access: public
See: ListCard

Card.LinkAccountCard

Kind: static property of Card
Access: public
See: LinkAccountCard

Bot.Extensions : object

扩展

Kind: static namespace of Bot

Extensions.TTSTemplate

扩展tts模版

Kind: static property of Extensions
Access: public
See: TTSTemplate

TTSTemplate.TTSTemplateItem

扩展tts模版项

Kind: static property of TTSTemplate
Access: public
See: TTSTemplateItem

Bot.Directive : object

Bot 可以返回指令

Kind: static namespace of Bot

Directive.AudioPlayer : object

音频指令

Kind: static namespace of Directive

AudioPlayer.Play

音频播放指令

Kind: static property of AudioPlayer
Access: public
See: Play

AudioPlayer.Stop

音频停止指令

Kind: static property of AudioPlayer
Access: public
See: Stop

AudioPlayer.PlayerInfo

音频播放信息类

Kind: static property of AudioPlayer
Access: public
See: PlayerInfo

AudioPlayer.Control : object

音频控制按钮

Kind: static namespace of AudioPlayer

Control.FavoriteButton

喜欢按钮控件

Kind: static property of Control
Access: public
See: FavoriteButton

Control.LyricButton

歌词按钮控件

Kind: static property of Control
Access: public
See: LyricButton

Control.NextButton

下一曲按钮控件

Kind: static property of Control
Access: public
See: NextButton

Control.PlayPauseButton

暂停播放按钮控件

Kind: static property of Control
Access: public
See: PlayPauseButton

Control.PreviousButton

上一曲按钮控件

Kind: static property of Control
Access: public
See: PreviousButton

Control.RadioButton

单选按钮控件

Kind: static property of Control
Access: public
See: RadioButton

Control.RecommendButton

推荐按钮控件

Kind: static property of Control
Access: public
See: RecommendButton

Control.RefreshButton

刷新按钮控件

Kind: static property of Control
Access: public
See: RefreshButton

Control.RepeatButton

单曲循环按钮控件

Kind: static property of Control
Access: public
See: RepeatButton

Control.ShowFavoriteListButton

展现收藏歌曲列表按钮控件

Kind: static property of Control
Access: public
See: ShowFavoriteListButton

Control.ShowPlayListButton

展现歌曲列表按钮控件

Kind: static property of Control
Access: public
See: ShowPlayListButton

Control.ThumbsUpDownButton

封面按钮控件

Kind: static property of Control
Access: public
See: ThumbsUpDownButton

Directive.VideoPlayer : object

视频指令

Kind: static namespace of Directive

VideoPlayer.Play

视频播放指令

Kind: static property of VideoPlayer
Access: public
See: Play

VideoPlayer.Stop

视频停止播放指令

Kind: static property of VideoPlayer
Access: public
See: Stop

VideoPlayer.VideoPlayerInfo

视频播放信息

Kind: static property of VideoPlayer
Access: public
See: VideoPlayerInfo

VideoPlayer.VideoPlayerInfoContent

视频播放信息内容

Kind: static property of VideoPlayer
Access: public
See: VideoPlayerInfoContent

Directive.Permission : object

用户权限

Kind: static namespace of Directive

Permission.AskForPermissionsConsent

用户授权指令

Kind: static property of Permission
Access: public
See: AskForPermissionsConsent

Directive.Record : object

录音

Kind: static namespace of Directive

Record.RecordSpeech

录音指令

Kind: static property of Record
Access: public
See: RecordSpeech

Directive.Display : object

模版渲染和用户提示指令

Kind: static namespace of Directive

Display.Hint

用户提示指令

Kind: static property of Display
Access: public
See: Hint

Display.RenderTemplate

模版渲染指令

Kind: static property of Display
Access: public
See: RenderTemplate

Display.RenderAudioList

模版音频列表指令

Kind: static property of Display
Access: public
See: RenderAudioList

Display.RenderVideoList

模版视频列表指令

Kind: static property of Display
Access: public
See: RenderVideoList

Display.PushStack

端入栈指令

Kind: static property of Display
Access: public
See: RenderVideoList

Display.RenderAudioPlayerInfo

渲染音频播放信息指令

Kind: static property of Display
Access: public
See: RenderAudioPlayerInfo

Display.RenderVideoPlayerInfo

渲染视频播放信息指令

Kind: static property of Display
Access: public
See: RenderVideoPlayerInfo

Display.Template : object

展示模版

Kind: static namespace of Display

Template.BodyTemplate1

文本展现模板

Kind: static property of Template
Access: public
See: BodyTemplate1

Template.BodyTemplate2

上图下文模版

Kind: static property of Template
Access: public
See: BodyTemplate2

Template.BodyTemplate3

左图右文模版

Kind: static property of Template
Access: public
See: BodyTemplate3

Template.BodyTemplate4

右图左文模版

Kind: static property of Template
Access: public
See: BodyTemplate4

Template.BodyTemplate5

图片模板

Kind: static property of Template
Access: public
See: BodyTemplate5

Template.BodyTemplate6

上图下文模版类

Kind: static property of Template
Access: public
See: BodyTemplate6

Template.ListTemplate1

横向列表模板

Kind: static property of Template
Access: public
See: ListTemplate1

Template.ListTemplate2

纵向列表模板

Kind: static property of Template
Access: public
See: ListTemplate2

Template.ListTemplate3

横向列表模板

Kind: static property of Template
Access: public
See: ListTemplate3

Template.ListTemplate4

纵向列表模板类

Kind: static property of Template
Access: public
See: ListTemplate4

Template.ListTemplateItem

模版列表项

Kind: static property of Template
Access: public
See: ListTemplateItem

Template.Tag : object

标签

Kind: static namespace of Template

####### Tag.AmountTag 数量标签

Kind: static property of Tag
Access: public
See: AmountTag

####### Tag.AuditionTag 试听标签

Kind: static property of Tag
Access: public
See: AuditionTag

####### Tag.HotTag 热门标签

Kind: static property of Tag
Access: public
See: HotTag

####### Tag.NewTag 最新标签

Kind: static property of Tag
Access: public
See: NewTag

####### Tag.CustomTag 自定义标签

Kind: static property of Tag
Access: public
See: CustomTag

####### Tag.FreeTag 免费标签

Kind: static property of Tag
Access: public
See: FreeTag

####### Tag.PayTag 支付标签

Kind: static property of Tag
Access: public
See: PayTag

####### Tag.PurchasedTag 购买标签

Kind: static property of Tag
Access: public
See: PurchasedTag

####### Tag.TimeTag 时间标签

Kind: static property of Tag
Access: public
See: TimeTag

####### Tag.VipTag VIP标签

Kind: static property of Tag
Access: public
See: VipTag

Directive.Pay : object

支付

Kind: static namespace of Directive

Pay.Charge

支付指令

Kind: static property of Pay
Access: public
See: Charge