Skip to content

Commit 60b800c

Browse files
authored
Merge pull request #25 from seymourtang/feature/convoai
feat:Add support for convo AI service
2 parents 48b3fee + fb603d4 commit 60b800c

37 files changed

+2860
-60
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
22
- repo: https://github.com/gitleaks/gitleaks
3-
rev: v8.21.2
3+
rev: v8.24.0
44
hooks:
55
- id: gitleaks

README.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,37 @@
99
<img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/AgoraIO-Community/agora-rest-client-go">
1010
</p>
1111

12-
`agora-rest-client-go`是用Go语言编写的一个开源项目,专门为 Agora REST API设计。它包含了 Agora 官方提供的REST API接口的包装和内部实现,可以帮助开发者更加方便的集成服务端Agora REST API。
12+
English | [简体中文](./README_ZH.md)
1313

14-
> 注意: 该SDK经过一些测试以确保其基本功能正常运作。然而,由于软件开发的复杂性,我们无法保证它是完全没有缺陷的。
15-
>
16-
>该SDK目前可能存在一些潜在的BUG或不稳定性。我们鼓励社区的开发者和用户积极参与,共同改进这个项目。
17-
18-
## 特性
19-
* 封装了Agora REST API的请求和响应处理,简化与Agora REST API 的通信流程
20-
* 当遇到 DNS 解析失败、网络错误或者请求超时等问题的时候,提供了自动切换最佳域名的能力,以保障请求 REST API 服务的可用性
21-
* 提供了易于使用的API,可轻松地实现调用 Agora REST API 的常见功能,如开启云录制、停止云录制等
22-
* 基于Go语言,具有高效性、并发性和可扩展性
23-
24-
## 支持的服务
25-
* [云端录制 Cloud Recording ](./services/cloudrecording/README.md)
26-
* [云端转码 Cloud Transcoder](./services/cloudtranscoder/README.md)
27-
28-
## 环境准备
29-
* [Go 1.18 或以上版本](https://go.dev/)
30-
* 在声网 [Console 平台](https://console.shengwang.cn/)申请的 App ID 和 App Certificate
31-
* 在声网 [Console 平台](https://console.shengwang.cn/)的 Basic Auth 认证信息
32-
* 在声网 [Console 平台](https://console.shengwang.cn/)开启相关的服务能力
33-
34-
## 安装
35-
使用以下命令从 GitHub 安装依赖:
14+
`agora-rest-client-go` is an open-source project written in Go, specifically designed for the Agora REST API. It includes wrappers and internal implementations of the official Agora REST API interfaces, making it easier for developers to integrate the server-side Agora REST API.
15+
16+
> [!IMPORTANT]
17+
This SDK has undergone some testing to ensure its basic functionality works correctly. However, due to the complexity of software development, we cannot guarantee it is completely free of defects. We encourage community developers and users to actively participate and help improve this project.
18+
19+
## Features
20+
* Encapsulates the request and response handling of the Agora REST API, simplifying the communication process with the Agora REST API.
21+
* Provides automatic switching to the best domain in case of DNS resolution failure, network errors, or request timeouts, ensuring the availability of the REST API service.
22+
* Offers easy-to-use APIs to easily implement common functions of the Agora REST API, such as starting and stopping cloud recording.
23+
* Based on Go language, it is efficient, concurrent, and scalable.
24+
25+
## Supported Services
26+
* [Cloud Recording](./services/cloudrecording/README.md)
27+
* [Cloud Transcoder](./services/cloudtranscoder/README.md)
28+
* [Conversational AI Engine](./services/convoai/README.md)
29+
30+
## Environment Setup
31+
* [Go 1.18 or later](https://go.dev/)
32+
* App ID and App Certificate obtained from the [Agora Console](https://console.shengwang.cn/)
33+
* Basic Auth credentials from the [Agora Console](https://console.shengwang.cn/)
34+
* Enable the relevant service capabilities on the [Agora Console](https://console.shengwang.cn/)
35+
36+
## Installation
37+
Install the dependency from GitHub using the following command:
3638
```shell
3739
go get -u github.com/AgoraIO-Community/agora-rest-client-go
3840
```
39-
## 使用示例
40-
以调用云录制服务为例:
41+
## Usage Example
42+
Here is an example of calling the cloud recording service:
4143

4244
```go
4345
package main
@@ -191,32 +193,32 @@ func main() {
191193
}
192194

193195
```
194-
更多的示例可在[Example](./examples) 查看
196+
For more examples, see [Example](./examples).
195197

196-
## 集成遇到困难,该如何联系声网获取协助
198+
## How to Contact Agora for Assistance if You Encounter Difficulties
197199

198-
> 方案1:如果您已经在使用声网服务或者在对接中,可以直接联系对接的销售或服务
200+
> Option 1: If you are already using Agora services or are in the process of integration, you can directly contact your sales or service representative.
199201
>
200-
> 方案2:发送邮件给 [[email protected]](mailto:[email protected]) 咨询
202+
> Option 2: Send an email to [[email protected]](mailto:[email protected]) for consultation.
201203
>
202-
> 方案3:扫码加入我们的微信交流群提问
204+
> Option 3: Scan the QR code to join our WeChat group for questions.
203205
>
204206
> <img src="https://download.agora.io/demo/release/SDHY_QA.jpg" width="360" height="360">
205207
---
206208

207-
## 贡献
208-
本项目欢迎并接受贡献。如果您在使用中遇到问题或有改进建议,请提出issue或向我们提交Pull Request
209+
## Contribution
210+
This project welcomes and accepts contributions. If you encounter any issues or have suggestions for improvements, please open an issue or submit a Pull Request.
209211

210-
# SemVer 版本规范
211-
本项目使用语义化版本号规范 (SemVer) 来管理版本。格式为 MAJOR.MINOR.PATCH
212+
# SemVer Versioning
213+
This project uses Semantic Versioning (SemVer) to manage versions. The format is MAJOR.MINOR.PATCH.
212214

213-
* MAJOR 版本号表示不向后兼容的重大更改。
214-
* MINOR 版本号表示向后兼容的新功能或增强。
215-
* PATCH 版本号表示向后兼容的错误修复和维护。
216-
有关详细信息,请参阅 [语义化版本](https://semver.org/lang/zh-CN/) 规范。
215+
* MAJOR version indicates incompatible changes.
216+
* MINOR version indicates backward-compatible new features or enhancements.
217+
* PATCH version indicates backward-compatible bug fixes and maintenance.
218+
For more details, please refer to the [Semantic Versioning](https://semver.org) specification.
217219

218-
## 参考
219-
* [Agora API 文档](https://doc.shengwang.cn/)
220+
## References
221+
* [Agora API Documentation](https://doc.shengwang.cn/)
220222

221-
## 许可证
222-
该项目使用MIT许可证,详细信息请参阅LICENSE文件。
223+
## License
224+
This project is licensed under the MIT License. For more details, please refer to the LICENSE file.

README_ZH.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Agora REST Client for Go
2+
<p>
3+
<img alt="GitHub License" src="https://img.shields.io/github/license/AgoraIO-Community/agora-rest-client-go">
4+
<a href="https://pkg.go.dev/github.com/AgoraIO-Community/agora-rest-client-go"><img src="https://pkg.go.dev/badge/github.com/AgoraIO-Community/agora-rest-client-go.svg" alt="Go Reference"></a>
5+
<a href="https://github.com/AgoraIO-Community/agora-rest-client-go/actions/workflows/go.yml"><img src="https://github.com/AgoraIO-Community/agora-rest-client-go/actions/workflows/go.yml/badge.svg" alt="Go Actions"></a>
6+
<a href="https://github.com/AgoraIO-Community/agora-rest-client-go/actions/workflows/gitee-sync.yml"><img alt="gitee-sync" src="https://github.com/AgoraIO-Community/agora-rest-client-go/actions/workflows/gitee-sync.yml/badge.svg?branch=main"></a>
7+
<img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/AgoraIO-Community/agora-rest-client-go">
8+
<img alt="GitHub" src="https://img.shields.io/github/v/release/AgoraIO-Community/agora-rest-client-go">
9+
<img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/AgoraIO-Community/agora-rest-client-go">
10+
</p>
11+
12+
[English](./README.md) | 简体中文
13+
14+
`agora-rest-client-go`是用Go语言编写的一个开源项目,专门为 Agora REST API设计。它包含了 Agora 官方提供的REST API接口的包装和内部实现,可以帮助开发者更加方便的集成服务端Agora REST API。
15+
16+
> [!IMPORTANT]
17+
该SDK经过一些测试以确保其基本功能正常运作。然而,由于软件开发的复杂性,我们无法保证它是完全没有缺陷的,我们鼓励社区的开发者和用户积极参与,共同改进这个项目。
18+
19+
## 特性
20+
* 封装了Agora REST API的请求和响应处理,简化与Agora REST API 的通信流程
21+
* 当遇到 DNS 解析失败、网络错误或者请求超时等问题的时候,提供了自动切换最佳域名的能力,以保障请求 REST API 服务的可用性
22+
* 提供了易于使用的API,可轻松地实现调用 Agora REST API 的常见功能,如开启云录制、停止云录制等
23+
* 基于Go语言,具有高效性、并发性和可扩展性
24+
25+
## 支持的服务
26+
* [云端录制 Cloud Recording](./services/cloudrecording/README.md)
27+
* [云端转码 Cloud Transcoder](./services/cloudtranscoder/README.md)
28+
* [对话式 AI 引擎 Conversationsal AI Engine](./services/convoai/README_ZH.md)
29+
30+
## 环境准备
31+
* [Go 1.18 或以上版本](https://go.dev/)
32+
* 在声网 [Console 平台](https://console.shengwang.cn/)申请的 App ID 和 App Certificate
33+
* 在声网 [Console 平台](https://console.shengwang.cn/)的 Basic Auth 认证信息
34+
* 在声网 [Console 平台](https://console.shengwang.cn/)开启相关的服务能力
35+
36+
## 安装
37+
使用以下命令从 GitHub 安装依赖:
38+
```shell
39+
go get -u github.com/AgoraIO-Community/agora-rest-client-go
40+
```
41+
## 使用示例
42+
以调用云录制服务为例:
43+
44+
```go
45+
package main
46+
47+
import (
48+
"context"
49+
"log"
50+
"time"
51+
52+
"github.com/AgoraIO-Community/agora-rest-client-go/agora"
53+
"github.com/AgoraIO-Community/agora-rest-client-go/agora/auth"
54+
"github.com/AgoraIO-Community/agora-rest-client-go/agora/domain"
55+
agoraLogger "github.com/AgoraIO-Community/agora-rest-client-go/agora/log"
56+
"github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording"
57+
cloudRecordingAPI "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/api"
58+
"github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/scenario/mixrecording"
59+
)
60+
61+
const (
62+
appId = "<your appId>"
63+
cname = "<your cname>"
64+
uid = "<your uid>"
65+
username = "<the username of basic auth credential>"
66+
password = "<the password of basic auth credential>"
67+
token = "<your token>"
68+
)
69+
70+
var storageConfig = &cloudRecordingAPI.StorageConfig{
71+
Vendor: 0,
72+
Region: 0,
73+
Bucket: "",
74+
AccessKey: "",
75+
SecretKey: "",
76+
FileNamePrefix: []string{
77+
"recordings",
78+
},
79+
}
80+
81+
func main() {
82+
// Initialize Agora Config
83+
config := &agora.Config{
84+
AppID: appId,
85+
Credential: auth.NewBasicAuthCredential(username, password),
86+
// Specify the region where the server is located. Options include CN, EU, AP, US.
87+
// The client will automatically switch to use the best domain based on the configured region.
88+
DomainArea: domain.CN,
89+
// Specify the log output level. Options include DebugLevel, InfoLevel, WarningLevel, ErrLevel.
90+
// To disable log output, set logger to DiscardLogger.
91+
Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel),
92+
}
93+
94+
// Initialize the cloud recording service client
95+
cloudRecordingClient, err := cloudrecording.NewClient(config)
96+
if err != nil {
97+
log.Fatal(err)
98+
}
99+
100+
// Call the Acquire API of the cloud recording service client
101+
acquireResp, err := cloudRecordingClient.MixRecording().
102+
Acquire(context.TODO(), cname, uid, &mixrecording.AcquireMixRecodingClientRequest{})
103+
// Handle non-business errors
104+
if err != nil {
105+
log.Fatal(err)
106+
}
107+
108+
// Handle business response
109+
if acquireResp.IsSuccess() {
110+
log.Printf("acquire success:%+v\n", acquireResp)
111+
} else {
112+
log.Fatalf("acquire failed:%+v\n", acquireResp)
113+
}
114+
115+
// Call the Start API of the cloud recording service client
116+
resourceId := acquireResp.SuccessRes.ResourceId
117+
startResp, err := cloudRecordingClient.MixRecording().
118+
Start(context.TODO(), resourceId, cname, uid, &mixrecording.StartMixRecordingClientRequest{
119+
Token: token,
120+
RecordingConfig: &cloudRecordingAPI.RecordingConfig{
121+
ChannelType: 1,
122+
StreamTypes: 2,
123+
MaxIdleTime: 30,
124+
AudioProfile: 2,
125+
TranscodingConfig: &cloudRecordingAPI.TranscodingConfig{
126+
Width: 640,
127+
Height: 640,
128+
FPS: 15,
129+
BitRate: 800,
130+
MixedVideoLayout: 0,
131+
BackgroundColor: "#000000",
132+
},
133+
SubscribeAudioUIDs: []string{
134+
"#allstream#",
135+
},
136+
SubscribeVideoUIDs: []string{
137+
"#allstream#",
138+
},
139+
},
140+
RecordingFileConfig: &cloudRecordingAPI.RecordingFileConfig{
141+
AvFileType: []string{
142+
"hls",
143+
"mp4",
144+
},
145+
},
146+
StorageConfig: storageConfig,
147+
})
148+
// Handle non-business errors
149+
if err != nil {
150+
log.Fatal(err)
151+
}
152+
153+
// Handle business response
154+
if startResp.IsSuccess() {
155+
log.Printf("start success:%+v\n", startResp)
156+
} else {
157+
log.Fatalf("start failed:%+v\n", startResp)
158+
}
159+
160+
sid := startResp.SuccessResponse.Sid
161+
// Query
162+
for i := 0; i < 6; i++ {
163+
queryResp, err := cloudRecordingClient.MixRecording().
164+
QueryHLSAndMP4(context.TODO(), resourceId, sid)
165+
// Handle non-business errors
166+
if err != nil {
167+
log.Fatal(err)
168+
}
169+
170+
// Handle business response
171+
if queryResp.IsSuccess() {
172+
log.Printf("query success:%+v\n", queryResp)
173+
} else {
174+
log.Printf("query failed:%+v\n", queryResp)
175+
}
176+
time.Sleep(time.Second * 10)
177+
}
178+
179+
// Call the Stop API of the cloud recording service client
180+
stopResp, err := cloudRecordingClient.MixRecording().
181+
Stop(context.TODO(), resourceId, sid, cname, uid, true)
182+
// Handle non-business errors
183+
if err != nil {
184+
log.Fatal(err)
185+
}
186+
187+
// Handle business response
188+
if stopResp.IsSuccess() {
189+
log.Printf("stop success:%+v\n", stopResp)
190+
} else {
191+
log.Printf("stop failed:%+v\n", stopResp)
192+
}
193+
}
194+
195+
```
196+
更多的示例可在[Example](./examples) 查看
197+
198+
## 集成遇到困难,该如何联系声网获取协助
199+
200+
> 方案1:如果您已经在使用声网服务或者在对接中,可以直接联系对接的销售或服务
201+
>
202+
> 方案2:发送邮件给 [[email protected]](mailto:[email protected]) 咨询
203+
>
204+
> 方案3:扫码加入我们的微信交流群提问
205+
>
206+
> <img src="https://download.agora.io/demo/release/SDHY_QA.jpg" width="360" height="360">
207+
---
208+
209+
## 贡献
210+
本项目欢迎并接受贡献。如果您在使用中遇到问题或有改进建议,请提出issue或向我们提交Pull Request。
211+
212+
# SemVer 版本规范
213+
本项目使用语义化版本号规范 (SemVer) 来管理版本。格式为 MAJOR.MINOR.PATCH。
214+
215+
* MAJOR 版本号表示不向后兼容的重大更改。
216+
* MINOR 版本号表示向后兼容的新功能或增强。
217+
* PATCH 版本号表示向后兼容的错误修复和维护。
218+
有关详细信息,请参阅 [语义化版本](https://semver.org/lang/zh-CN/) 规范。
219+
220+
## 参考
221+
* [Agora API 文档](https://doc.shengwang.cn/)
222+
223+
## 许可证
224+
该项目使用MIT许可证,详细信息请参阅LICENSE文件。

agora/auth/basic.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ type BasicAuthCredential struct {
1212
// Ensure BasicAuthCredential implements Credential
1313
var _ Credential = (*BasicAuthCredential)(nil)
1414

15+
// @brief Create a new BasicAuthCredential instance
16+
//
17+
// @note Customer ID and customer secret obtained from the Agora console, used for HTTP basic authentication
18+
//
19+
// @param username Customer ID obtained from the Agora console
20+
//
21+
// @param password Customer secret obtained from the Agora console
22+
//
23+
// @return Returns the BasicAuthCredential instance
24+
//
25+
// @since v0.7.0
1526
func NewBasicAuthCredential(username string, password string) *BasicAuthCredential {
1627
return &BasicAuthCredential{
1728
username: username,

agora/config.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ import (
99
)
1010

1111
type Config struct {
12-
AppID string
12+
// Agora AppID
13+
AppID string
14+
// Timeout for HTTP requests
1315
HttpTimeout time.Duration
14-
Credential auth.Credential
16+
// Credential for accessing the Agora service.
17+
//
18+
// Available credential types:
19+
//
20+
// - BasicAuthCredential: See auth.NewBasicAuthCredential for details
21+
Credential auth.Credential
1522

23+
// Domain area for the REST Client. See domain.Area for details.
1624
DomainArea domain.Area
17-
Logger log.Logger
25+
26+
// Logger for the REST Client
27+
//
28+
// Implement the log.Logger interface in your project to output REST Client logs to your logging component.
29+
//
30+
// Alternatively, you can use the default logging component. See log.NewDefaultLogger for details.
31+
Logger log.Logger
1832
}

0 commit comments

Comments
 (0)