bot

package
v0.0.0-...-852b98d Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: Apache-2.0 Imports: 18 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPError

func HTTPError(w http.ResponseWriter, logMsg string, err string, errCode int)

func IsValidRequest

func IsValidRequest(w http.ResponseWriter, r *http.Request) bool

IsValidRequest handles all the necessary steps to validate that an incoming http.Request has actually come from the DuerOS service. If an error occurs during the validation process, an http.Error will be written to the provided http.ResponseWriter. The required steps for request validation can be found on this page: https://dueros.baidu.com/didp/doc/dueros-bot-platform/dbp-deploy/authentication_markdown

Types

type Application

type Application struct {
	AppId              string
	DisableCertificate bool
	DisableVerifyJson  bool
	Handler            func(rawRequest string) string
}

func (*Application) ServeHTTP

func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request)

创建一个HTTP服务

func (*Application) Start

func (this *Application) Start(host string)

启动HTTP服务

func (*Application) Verify

func (this *Application) Verify(w http.ResponseWriter, r *http.Request) bool

验证请求是否合法

type Bot

type Bot struct {
	Request  interface{}     // 对当前request的封装,需要在使用时断言,判断当前的类型
	Session  *model.Session  // 对session的封装
	Response *model.Response // 对技能返回的封装
	// contains filtered or unexported fields
}

技能基础类

func NewBot

func NewBot() *Bot

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

func (*Bot) AddDefaultEventListener

func (this *Bot) AddDefaultEventListener(fn func(bot *Bot, request interface{}))

添加事件默认处理函数 比如,在播放视频时,技能会收到各种事件的上报,如果不想一一处理可以使用这个来添加处理

func (*Bot) AddEventListener

func (this *Bot) AddEventListener(eventName string, fn func(bot *Bot, request interface{}))

添加对事件的处理函数

func (*Bot) AddIntentHandler

func (this *Bot) AddIntentHandler(intentName string, fn func(bot *Bot, request *model.IntentRequest))

添加对intent的处理函数

func (*Bot) Handler

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

根据每个请求分别处理

func (*Bot) OnAudioPlaybackFinished

func (this *Bot) OnAudioPlaybackFinished(fn func(bot *Bot, request *model.AudioPlayerEventRequest))

音频播放完成事件

func (*Bot) OnAudioPlaybackNearlyFinished

func (this *Bot) OnAudioPlaybackNearlyFinished(fn func(bot *Bot, request *model.AudioPlayerEventRequest))

音频快要播放结束上报的事件

func (*Bot) OnAudioPlaybackStarted

func (this *Bot) OnAudioPlaybackStarted(fn func(bot *Bot, request *model.AudioPlayerEventRequest))

音频开始播放事件

func (*Bot) OnAudioPlaybackStopped

func (this *Bot) OnAudioPlaybackStopped(fn func(bot *Bot, request *model.AudioPlayerEventRequest))

音频停止播放事件

func (*Bot) OnAudioRrogressReportIntevalElapsed

func (this *Bot) OnAudioRrogressReportIntevalElapsed(fn func(bot *Bot, request *model.AudioPlayerEventRequest))

音频周期上报播放进度

func (*Bot) OnDisplayElementSelected

func (this *Bot) OnDisplayElementSelected(fn func(bot *Bot, request *model.EventRequest))

ListTemplate 列表选择事件 Display.ButtonClicked 事件 https://dueros.baidu.com/didp/doc/dueros-bot-platform/dbp-custom/display-template_markdown#Display.ElementSelected%E4%BA%8B%E4%BB%B6

func (*Bot) OnLaunchRequest

func (this *Bot) OnLaunchRequest(fn func(bot *Bot, request *model.LaunchRequest))

打开技能时的处理

func (*Bot) OnLinkAccountSuccessed

func (this *Bot) OnLinkAccountSuccessed(fn func(bot *Bot, request *model.EventRequest))

LinkAccountSucceeded 事件 ```javascript

{
   "type": "Connections.Response",
   "name": "LinkAccountSucceeded",
   "requestId": "{{STRING}}",
   "timestamp": {{INT32}},
   "token": "{{STRING}}"
}

```

func (*Bot) OnScreenLinkClicked

func (this *Bot) OnScreenLinkClicked(fn func(bot *Bot, request *model.EventRequest))

Screen.LinkClicked事件 https://dueros.baidu.com/didp/doc/dueros-bot-platform/dbp-custom/cards_markdown#Screen.LinkClicked%E4%BA%8B%E4%BB%B6

{
   "type": "Screen.LinkClicked",
   "url": "{{STRING}}",
   "requestId": "{{STRING}}",
   "timestamp": {{INT32}}
   "token": "{{STRING}}"
}

func (*Bot) OnSessionEndedRequest

func (this *Bot) OnSessionEndedRequest(fn func(bot *Bot, request *model.SessionEndedRequest))

技能关闭的处理,比如可以做一些清理的工作 TIP: 根据协议,技能关闭返回的结果,DuerOS不会返回给用户。

func (*Bot) OnVideoPlaybackFinished

func (this *Bot) OnVideoPlaybackFinished(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频播放完成事件

func (*Bot) OnVideoPlaybackNearlyFinished

func (this *Bot) OnVideoPlaybackNearlyFinished(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频快要播放结束上报的事件

func (*Bot) OnVideoPlaybackStarted

func (this *Bot) OnVideoPlaybackStarted(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频开始播放事件

func (*Bot) OnVideoPlaybackStopped

func (this *Bot) OnVideoPlaybackStopped(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频停止播放事件

func (*Bot) OnVideoPlayerScheduledStopReached

func (this *Bot) OnVideoPlayerScheduledStopReached(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频自动暂停后上报

func (*Bot) OnVideoRrogressReportIntevalElapsed

func (this *Bot) OnVideoRrogressReportIntevalElapsed(fn func(bot *Bot, request *model.VideoPlayerEventRequest))

视频周期上报播放进度

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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