Help us shape the future of Go! Take the 2026 Go Developer Survey

wulai-openapi-sdk-golang

module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0

README

Wulai Openapi SDK for Go

build status codecov GitHub license

欢迎使用 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

Directories

Path Synopsis
example
scenes1 command
scenes2 command
scenes3 command
scenes4 command
scenes5 command
scenes6 command
services
lc

Jump to

Keyboard shortcuts

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