Bot基类. 请继承此类
Kind: global class
- Bot
- new Bot(postData)
- instance
- .addLaunchHandler(handler) ⇒
Bot
- .addSessionEndedHandler(handler) ⇒
Bot
- .addIntentHandler(intent, handler) ⇒
Bot
- .addEventListener(event, handler) ⇒
Bot
- .addDefaultEventListener(handler) ⇒
Bot
- .initCertificate(headers, body) ⇒
Certificate
- .getIntentName() ⇒
string
|null
- .getSessionAttribute(field, defaultValue) ⇒
Mixied
- .setSessionAttribute(field, value, defaultValue) ⇒
null
- .clearSessionAttribute() ⇒
null
- .getSlot(field, index) ⇒
string
- .setSlot(field, value, index) ⇒
null
- .waitAnswer() ⇒
null
- .endSession()
- .setPrivateKey(filename) ⇒
Promise
- .setExpectSpeech(expectSpeech)
- .endDialog()
- .isSupportDisplay() ⇒
boolean
- .isSupportAudioPlayer() ⇒
boolean
- .isSupportVideoPlayer() ⇒
boolean
- .run(build) ⇒
Promise
- .addExpectSlotResponse(slot)
- .getApiAccessToken() ⇒
string
- .getApiEndPoint() ⇒
string
- .getUserProfile() ⇒
Promise
- .getRecordSpeech(audioToken) ⇒
Promise
- .getDeviceLocation() ⇒
Promise
- .callSmarthomePrinter(data) ⇒
Promise
- .sendMateappNotification(data) ⇒
Promise
- .addLaunchHandler(handler) ⇒
- static
- .Card :
object
- .Extensions :
object
- .Directive :
object
- .AudioPlayer :
object
- .VideoPlayer :
object
- .Permission :
object
- .Record :
object
- .Display :
object
- .Pay :
object
- .AudioPlayer :
- .Card :
构造函数,以及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 |
初始化认证校验
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":""}'
);
获取DuerOS请求中的意图名
Kind: instance method of Bot
Access: public
获取session的一个字段对应的值
Kind: instance method of Bot
Access: public
Param | Type | Default | Description |
---|---|---|---|
field | string |
null |
字段名 |
defaultValue | Mixed |
|
默认值 当此字段没有值时,返回defaultValue |
设置session的一个字段的值
Kind: instance method of Bot
Access: public
Param | Type | Default | Description |
---|---|---|---|
field | string |
字段名 | |
value | Mixed |
字段对应的值 | |
defaultValue | Mixed |
|
默认值 当value为空时,使用defaultValue |
清空session的所有字段
Kind: instance method of Bot
Access: public
根据槽位名获取槽位对应的值
Kind: instance method of Bot
Access: public
Param | Type | Default | Description |
---|---|---|---|
field | string |
槽位名 | |
index | Integer |
0 |
第几个intent,默认第一个 |
设置槽位的值。如果该槽位不存在,新增一个槽位名,并设置对于的值
Kind: instance method of Bot
Access: public
Param | Type | Default | Description |
---|---|---|---|
field | string |
槽位名 | |
value | string |
值 | |
index | Integer |
0 |
第几个intent,默认第一个 |
设置多轮继续,等待用户回复
Kind: instance method of Bot
Access: public
设置多轮结束,此时bot结束多轮对话
Kind: instance method of Bot
Access: public
设置私钥
Kind: instance method of Bot
Param | Type | Description |
---|---|---|
filename | string |
私钥路径 |
通过控制expectSpeech来控制麦克风开
Kind: instance method of Bot
Param | Type | Description |
---|---|---|
expectSpeech | boolean |
是否开启麦克风 |
告诉DuerOS,需要结束对话
Kind: instance method of Bot
检测Display的数据是否存在
Kind: instance method of Bot
Access: public
检测AudioPlayer对象是否存在
Kind: instance method of Bot
Access: public
检测VideoPlayer对象是否存在
Kind: instance method of Bot
Access: public
bot执行的入口
Kind: instance method of Bot
Access: public
Param | Type | Default | Description |
---|---|---|---|
build | boolean |
true |
是否需要打包response,输出JSON String |
技能所期待的用户回复,技能将该信息反馈给DuerOS,有助于DuerOS在语音识别以及识别纠错时向该信息提权
Kind: instance method of Bot
Param | Type | Description |
---|---|---|
slot | string |
槽位类型回复表达的槽位名称。 |
获取apiAccessToken
Kind: instance method of Bot
获取apiEndPoint
Kind: instance method of Bot
获取用户百度账号信息
Kind: instance method of Bot
获取用户录音数据
Kind: instance method of Bot
Param | Type | Description |
---|---|---|
audioToken | string |
RecordSpeechFinished事件中的audioToken |
获取用户地理位置信息
Kind: instance method of Bot
调用智能家居打印机服务
Kind: instance method of Bot
Param | Type |
---|---|
data | object |
小度音箱app通知接口
Kind: instance method of Bot
Param | Type | Description |
---|---|---|
data | Object |
参数对象 |
Bot可以返回的卡片
Kind: static namespace of Bot
Kind: static property of Card
Access: public
See: TextCard
Kind: static property of Card
Access: public
See: ImageCard
Kind: static property of Card
Access: public
See: StandardCard
Kind: static property of Card
Access: public
See: ListCard
Kind: static property of Card
Access: public
See: LinkAccountCard
扩展
Kind: static namespace of Bot
- .Extensions :
object
扩展tts模版
Kind: static property of Extensions
Access: public
See: TTSTemplate
扩展tts模版项
Kind: static property of TTSTemplate
Access: public
See: TTSTemplateItem
Bot 可以返回指令
Kind: static namespace of Bot
- .Directive :
object
- .AudioPlayer :
object
- .VideoPlayer :
object
- .Permission :
object
- .Record :
object
- .Display :
object
- .Pay :
object
- .AudioPlayer :
音频指令
Kind: static namespace of Directive
- .AudioPlayer :
object
音频播放指令
Kind: static property of AudioPlayer
Access: public
See: Play
音频停止指令
Kind: static property of AudioPlayer
Access: public
See: Stop
音频播放信息类
Kind: static property of AudioPlayer
Access: public
See: PlayerInfo
音频控制按钮
Kind: static namespace of AudioPlayer
- .Control :
object
喜欢按钮控件
Kind: static property of Control
Access: public
See: FavoriteButton
歌词按钮控件
Kind: static property of Control
Access: public
See: LyricButton
下一曲按钮控件
Kind: static property of Control
Access: public
See: NextButton
暂停播放按钮控件
Kind: static property of Control
Access: public
See: PlayPauseButton
上一曲按钮控件
Kind: static property of Control
Access: public
See: PreviousButton
单选按钮控件
Kind: static property of Control
Access: public
See: RadioButton
推荐按钮控件
Kind: static property of Control
Access: public
See: RecommendButton
刷新按钮控件
Kind: static property of Control
Access: public
See: RefreshButton
单曲循环按钮控件
Kind: static property of Control
Access: public
See: RepeatButton
展现收藏歌曲列表按钮控件
Kind: static property of Control
Access: public
See: ShowFavoriteListButton
展现歌曲列表按钮控件
Kind: static property of Control
Access: public
See: ShowPlayListButton
封面按钮控件
Kind: static property of Control
Access: public
See: ThumbsUpDownButton
视频指令
Kind: static namespace of Directive
视频播放指令
Kind: static property of VideoPlayer
Access: public
See: Play
视频停止播放指令
Kind: static property of VideoPlayer
Access: public
See: Stop
视频播放信息
Kind: static property of VideoPlayer
Access: public
See: VideoPlayerInfo
视频播放信息内容
Kind: static property of VideoPlayer
Access: public
See: VideoPlayerInfoContent
用户权限
Kind: static namespace of Directive
用户授权指令
Kind: static property of Permission
Access: public
See: AskForPermissionsConsent
录音
Kind: static namespace of Directive
录音指令
Kind: static property of Record
Access: public
See: RecordSpeech
模版渲染和用户提示指令
Kind: static namespace of Directive
- .Display :
object
用户提示指令
Kind: static property of Display
Access: public
See: Hint
模版渲染指令
Kind: static property of Display
Access: public
See: RenderTemplate
模版音频列表指令
Kind: static property of Display
Access: public
See: RenderAudioList
模版视频列表指令
Kind: static property of Display
Access: public
See: RenderVideoList
端入栈指令
Kind: static property of Display
Access: public
See: RenderVideoList
渲染音频播放信息指令
Kind: static property of Display
Access: public
See: RenderAudioPlayerInfo
渲染视频播放信息指令
Kind: static property of Display
Access: public
See: RenderVideoPlayerInfo
展示模版
Kind: static namespace of Display
- .Template :
object
文本展现模板
Kind: static property of Template
Access: public
See: BodyTemplate1
上图下文模版
Kind: static property of Template
Access: public
See: BodyTemplate2
左图右文模版
Kind: static property of Template
Access: public
See: BodyTemplate3
右图左文模版
Kind: static property of Template
Access: public
See: BodyTemplate4
图片模板
Kind: static property of Template
Access: public
See: BodyTemplate5
上图下文模版类
Kind: static property of Template
Access: public
See: BodyTemplate6
横向列表模板
Kind: static property of Template
Access: public
See: ListTemplate1
纵向列表模板
Kind: static property of Template
Access: public
See: ListTemplate2
横向列表模板
Kind: static property of Template
Access: public
See: ListTemplate3
纵向列表模板类
Kind: static property of Template
Access: public
See: ListTemplate4
模版列表项
Kind: static property of Template
Access: public
See: ListTemplateItem
标签
Kind: static namespace of Template
- .Tag :
object
####### 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
支付
Kind: static namespace of Directive
支付指令