Coder Social home page Coder Social logo

bot-sdk-go's Introduction

度秘BOT SDK for GO

这是一个帮助开发Bot的SDK,针对php、java、node.js也有对应的版本.SDK封装了对session、nlu、result的处理,使用sdk可以避免由于BOT的协议的升级带来一些麻烦。这个SDK会与DuerOS的协议一起升级,会最大限度减少对您开发bot的影响。

通过bot-sdk可以快速的开发bot

我们的目标是通过使用bot-sdk,可以迅速的开发一个bot,而不必过多去关注DuerOS对Bot的复杂协议。我们提供如下功能:

  • 封装了DuerOS的request和response
  • 提供了session简化接口
  • 提供了nlu简化接口
    • slot 操作
    • nlu理解交互接口(ask)
  • 提供了多轮对话开发接口
  • 提供了事件监听接口
  • 展现模板、视频、音频指令的封装

安装、使用BOT SDK进行开发

度秘BOT SDK使用执行如下命令进行安装:

go get github.com/dueros/bot-sdk-go

为了开始使用BOT SDK,你需要先新建一个main文件,比如文件名是main.go。

import (
	dueros "github.com/dueros/bot-sdk-go/bot"
	"github.com/dueros/bot-sdk-go/bot/directive/display"
	"github.com/dueros/bot-sdk-go/bot/directive/display/template"
	"github.com/dueros/bot-sdk-go/bot/model"
)

func main() {

	application := dueros.Application{AppId: "you bot id", Handler: func(body string) string {
		bot := dueros.NewBot(body)

        // 意图处理函数
		bot.AddIntentHandler("test.inquiry888",
			func(this *dueros.Bot, request *model.IntentRequest) {
				template := template.NewBodyTemplate1()
				template.SetTitle("title")
				template.SetPlainContent("欢迎查询")
				template.SetBackgroundImageUrl("http://www.baidu.com")
				directive := display.NewRenderTemplate(template)

				this.Response.Ask("欢迎查询").Command(directive)
			})

        // 技能被打开的请求处理
		bot.OnLaunchRequest(func(this *dueros.Bot, request *model.LaunchRequest) {
			this.Response.Tell("欢迎使用查个税")
		})

		return bot.Run()
	}}
	application.Start(":8888")
}

下一步,我们处理意图。Bot-sdk提供了一个函数来handle这些意图。比如,查询个税,创建一个handler,在构造函数中添加:

这里AddIntentHandler可以用来建立(intent) => handler的映射,第一个参数是条件,如果满足则执行对应的回调函数(第二个参数)。 其中,this指向当前的Bot,通过Response来进行回复。Ask可以用来向用户澄清,Command可以用来返回一个指令。

API 文档

bot-sdk-go's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.