Wulai Openapi SDK for Go

欢迎使用 Wulai Openapi SDK for Go。
环境要求
- 您的系统需要达到 [环境要求][Requirements], 例如,安装了不低于 1.10.x 版本的 Go 环境。
安装
使用 go get 下载安装 SDK
$ go get -u github.com/laiye-ai/wulai-openapi-sdk-golang
如果您使用了 glide 管理依赖,您也可以使用 glide 来安装 SDK
$ glide get github.com/laiye-ai/wulai-openapi-sdk-golang
快速使用
在您开始之前,您需要注册帐户并获取您的凭证。
创建HTTP客户端
package main
import (
"github.com/laiye-ai/wulai-openapi-sdk-golang/services/common"
)
func main() {
credential := common.NewCredential("secret", "pubkey")
client := common.NewClient(credential)
client.Post("http://openapi.wul.ai", []byte("input"))
}
创建用户,对机器人发起问答
package main
import (
"github.com/laiye-ai/wulai-openapi-sdk-golang/services/common/log"
"github.com/laiye-ai/wulai-openapi-sdk-golang/services/wulai"
)
func main() {
//实例化客户端
wulaiClient := wulai.NewClient("secret", "pubkey")
wulaiClient.Version = "v2"
wulaiClient.SetDebug(true) //开启调试
log.Infof("[wulaiClient]%+v\n", wulaiClient)
user, err := wulaiClient.UserCreate("test_golang_api", "", "test_golang_api")
if err != nil {
log.Fatalf("user Create test reuslt:%s", err.Error())
}
log.Infof("[创建用户]: %+v\n", user)
//消息类型[文本消息]
textMsg := &wulai.Text{
Content: "您好",
}
//发起问答
botResp, err := wulaiClient.MsgBotResponse(user.UserID, textMsg, "预留信息")
if err != nil {
log.Fatalf("user Create test reuslt:%s", err.Error())
}
log.Infof("[机器人回复]%+v\n", botResp)
}
协议说明
网络协议: HTTP
请求方式: POST
请求、响应数据格式: JSON