### Running CloudRecording Examples Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudrecording/README.md Executes the Go application to start cloud recording. Supports different modes (mix, individual, web) and specific scenarios within each mode. ```go go run main.go -mode=mix -mix_scene= go run main.go -mode=individual -individual_scene= go run main.go -mode=web -web_scene= ``` -------------------------------- ### Running CloudRecording Example Modes Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudrecording/README_ZH.md Demonstrates how to execute the CloudRecording example project using different recording modes and scene configurations. Supports mixed, individual, and web recording scenarios with specific scene options. ```go go run main.go -mode=mix -mix_scene= go run main.go -mode=individual -individual_scene= go run main.go -mode=web -web_scene= ``` -------------------------------- ### Install Agora REST Client for Go Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/README.md Installs the agora-rest-client-go dependency from GitHub using the go get command. ```shell go get -u github.com/AgoraIO-Community/agora-rest-client-go ``` -------------------------------- ### Cloud Recording Service Example Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/README.md Demonstrates the complete workflow for using the Agora Cloud Recording service in Go. This includes initializing the client with authentication and domain settings, acquiring a recording resource, starting a recording with various configurations (transcoding, file types, storage), periodically querying the recording status, and finally stopping the recording. It also shows how to handle both business logic errors and non-business errors. ```go package main import ( "context" "log" "time" "github.com/AgoraIO-Community/agora-rest-client-go/agora/auth" "github.com/AgoraIO-Community/agora-rest-client-go/agora/domain" agoraLogger "github.com/AgoraIO-Community/agora-rest-client-go/agora/log" "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording" cloudRecordingAPI "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/api" "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/req" ) const ( appId = "" cname = "" uid = "" username = "" password = "" token = "" ) var storageConfig = &cloudRecordingAPI.StorageConfig{ Vendor: 0, Region: 0, Bucket: "", AccessKey: "", SecretKey: "", FileNamePrefix: []string{ "recordings", }, } func main() { // Initialize Cloud Recording Config config := &cloudrecording.Config{ AppID: appId, Credential: auth.NewBasicAuthCredential(username, password), // Specify the region where the server is located. Options include CN, EU, AP, US. // The client will automatically switch to use the best domain based on the configured region. DomainArea: domain.CN, // Specify the log output level. Options include DebugLevel, InfoLevel, WarningLevel, ErrLevel. // To disable log output, set logger to DiscardLogger. Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), } // Initialize the cloud recording service client cloudRecordingClient, err := cloudrecording.NewClient(config) if err != nil { log.Fatal(err) } // Call the Acquire API of the cloud recording service client aquireResp, err := cloudRecordingClient.MixRecording(). Acquire(context.TODO(), cname, uid, &req.AcquireMixRecodingClientRequest{}) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if acquireResp.IsSuccess() { log.Printf("acquire success:%+v\n", acquireResp) } else { log.Fatalf("acquire failed:%+v\n", acquireResp) } // Call the Start API of the cloud recording service client resourceId := acquireResp.SuccessRes.ResourceId startResp, err := cloudRecordingClient.MixRecording(). Start(context.TODO(), resourceId, cname, uid, &req.StartMixRecordingClientRequest{ Token: token, RecordingConfig: &cloudRecordingAPI.RecordingConfig{ ChannelType: 1, StreamTypes: 2, MaxIdleTime: 30, AudioProfile: 2, TranscodingConfig: &cloudRecordingAPI.TranscodingConfig{ Width: 640, Height: 640, FPS: 15, BitRate: 800, MixedVideoLayout: 0, BackgroundColor: "#000000", }, SubscribeAudioUIDs: []string{ "#allstream#", }, SubscribeVideoUIDs: []string{ "#allstream#", }, }, RecordingFileConfig: &cloudRecordingAPI.RecordingFileConfig{ AvFileType: []string{ "hls", "mp4", }, }, StorageConfig: storageConfig, }) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if startResp.IsSuccess() { log.Printf("start success:%+v\n", startResp) } else { log.Fatalf("start failed:%+v\n", startResp) } sid := startResp.SuccessResponse.Sid // Query for i := 0; i < 6; i++ { queryResp, err := cloudRecordingClient.MixRecording(). QueryHLSAndMP4(context.TODO(), resourceId, sid) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if queryResp.IsSuccess() { log.Printf("query success:%+v\n", queryResp) } else { log.Printf("query failed:%+v\n", queryResp) } time.Sleep(time.Second * 10) } // Call the Stop API of the cloud recording service client stopResp, err := cloudRecordingClient.MixRecording(). Stop(context.TODO(), resourceId, sid, cname, uid, true) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if stopResp.IsSuccess() { log.Printf("stop success:%+v\n", stopResp) } else { log.Printf("stop failed:%+v\n", stopResp) } } ``` -------------------------------- ### Start Cloud Recording Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README.md Initiates the cloud recording process after acquiring a Resource ID. This method allows configuration of recording parameters, file storage, and transcoding settings. The example shows a comprehensive setup for starting the recording. ```go startResp, err := cloudRecordingClient.Start(ctx, resp.SuccessRes.ResourceId, mode, &cloudRecordingAPI.StartReqBody{ Cname: cname, Uid: uid, ClientRequest: &cloudRecordingAPI.StartClientRequest{ Token: token, RecordingConfig: &cloudRecordingAPI.RecordingConfig{ ChannelType: 1, StreamTypes: 2, AudioProfile: 2, MaxIdleTime: 30, TranscodingConfig: &cloudRecordingAPI.TranscodingConfig{ Width: 640, Height: 260, FPS: 15, BitRate: 500, MixedVideoLayout: 0, BackgroundColor: "#000000", }, SubscribeAudioUIDs: []string{ "22", "456", }, SubscribeVideoUIDs: []string{ "22", "456", }, }, RecordingFileConfig: &cloudCloudRecordingAPI.RecordingFileConfig{ AvFileType: []string{ "hls", }, }, StorageConfig: &cloudRecordingAPI.StorageConfig{ Vendor: 2, Region: 3, Bucket: "xxx", AccessKey: "xxxx", SecretKey: "xxx", FileNamePrefix: []string{ "xx1", "xx2", }, }, }) if err != nil { log.Fatalln(err) } if startResp.IsSuccess() { log.Printf("success:%+v", &startResp.SuccessResponse) } else { log.Printf("failed:%+v", &startResp.ErrResponse) } ``` -------------------------------- ### Running Cloud Transcoder Scenarios Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudtranscoder/README_ZH.md Commands to execute the Agora Cloud Transcoder example project for different transcoding scenarios. The `-scene` flag specifies the desired transcoding configuration. ```go go run main.go -scene=single_channel_rtc_pull_mixer_rtc_push go run main.go -scene=single_channel_rtc_pull_fullchannel_audiomixer_rtc_push ``` -------------------------------- ### Execute Example Project Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README_ZH.md Command to run the example project. It takes the TTS vendor as an argument, allowing selection between different TTS providers. ```bash go run main.go --ttsVendor= --serviceRegion=1 ``` -------------------------------- ### Install Agora REST Client for Go Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/README_ZH.md This snippet shows how to install the Agora REST Client for Go using the go get command. It ensures you have the latest version of the library for your Go project. ```shell go get -u github.com/AgoraIO-Community/agora-rest-client-go ``` -------------------------------- ### Cloud Recording Service Integration Example Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/README_ZH.md This Go code demonstrates how to use the Agora REST Client to manage cloud recordings. It includes initializing the client with authentication and domain settings, acquiring a recording resource, starting a recording with various configurations (transcoding, file types, storage), querying the recording status, and finally stopping the recording. It also shows how to handle both business logic errors and non-business errors. ```go package main import ( "context" "log" "time" "github.com/AgoraIO-Community/agora-rest-client-go/agora/auth" "github.com/AgoraIO-Community/agora-rest-client-go/agora/domain" agoraLogger "github.com/AgoraIO-Community/agora-rest-client-go/agora/log" "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording" cloudRecordingAPI "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/api" "github.com/AgoraIO-Community/agora-rest-client-go/services/cloudrecording/req" ) const ( appId = "" cname = "" uid = "" username = "" password = "" token = "" ) var storageConfig = &cloudRecordingAPI.StorageConfig{ Vendor: 0, Region: 0, Bucket: "", AccessKey: "", SecretKey: "", FileNamePrefix: []string{ "recordings", }, } func main() { // Initialize Cloud Recording Config config := &cloudrecording.Config{ AppID: appId, Credential: auth.NewBasicAuthCredential(username, password), // Specify the region where the server is located. Options include CN, EU, AP, US. // The client will automatically switch to use the best domain based on the configured region. DomainArea: domain.CN, // Specify the log output level. Options include DebugLevel, InfoLevel, WarningLevel, ErrLevel. // To disable log output, set logger to DiscardLogger. Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), } // Initialize the cloud recording service client cloudRecordingClient, err := cloudrecording.NewClient(config) if err != nil { log.Fatal(err) } // Call the Acquire API of the cloud recording service client aquireResp, err := cloudRecordingClient.MixRecording(). Acquire(context.TODO(), cname, uid, &req.AcquireMixRecodingClientRequest{}) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if acquireResp.IsSuccess() { log.Printf("acquire success:%+v\n", acquireResp) } else { log.Fatalf("acquire failed:%+v\n", acquireResp) } // Call the Start API of the cloud recording service client resourceId := acquireResp.SuccessRes.ResourceId startResp, err := cloudRecordingClient.MixRecording(). Start(context.TODO(), resourceId, cname, uid, &req.StartMixRecordingClientRequest{ Token: token, RecordingConfig: &cloudRecordingAPI.RecordingConfig{ ChannelType: 1, StreamTypes: 2, MaxIdleTime: 30, AudioProfile: 2, TranscodingConfig: &cloudRecordingAPI.TranscodingConfig{ Width: 640, Height: 640, FPS: 15, BitRate: 800, MixedVideoLayout: 0, BackgroundColor: "#000000", }, SubscribeAudioUIDs: []string{ "#allstream#", }, SubscribeVideoUIDs: []string{ "#allstream#", }, }, RecordingFileConfig: &cloudRecordingAPI.RecordingFileConfig{ AvFileType: []string{ "hls", "mp4", }, }, StorageConfig: storageConfig, }) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if startResp.IsSuccess() { log.Printf("start success:%+v\n", startResp) } else { log.Fatalf("start failed:%+v\n", startResp) } sid := startResp.SuccessResponse.Sid // Query for i := 0; i < 6; i++ { queryResp, err := cloudRecordingClient.MixRecording(). QueryHLSAndMP4(context.TODO(), resourceId, sid) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if queryResp.IsSuccess() { log.Printf("query success:%+v\n", queryResp) } else { log.Printf("query failed:%+v\n", queryResp) } time.Sleep(time.Second * 10) } // Call the Stop API of the cloud recording service client stopResp, err := cloudRecordingClient.MixRecording(). Stop(context.TODO(), resourceId, sid, cname, uid, true) // Handle non-business errors if err != nil { log.Fatal(err) } // Handle business response if stopResp.IsSuccess() { log.Printf("stop success:%+v\n", stopResp) } else { log.Printf("stop failed:%+v\n", stopResp) } } ``` -------------------------------- ### Basic Environment Variables Setup Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README.md Sets up essential environment variables for the Agora Conversational AI service, including App ID, authentication credentials, and agent token. ```bash export APP_ID= export BASIC_AUTH_USERNAME= export BASIC_AUTH_PASSWORD= export CONVOAI_TOKEN= export CONVOAI_CHANNEL= export CONVOAI_AGENT_RTC_UID= ``` -------------------------------- ### Running CloudTranscoder Scenarios Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudtranscoder/README.md Executes the CloudTranscoder example project with different transcoding scenarios specified by the '-scene' flag. Supports composite transcoding and full channel audio mixing transcoding. ```go go run main.go -scene=single_channel_rtc_pull_mixer_rtc_push go run main.go -scene=single_channel_rtc_pull_fullchannel_audiomixer_rtc_push ``` -------------------------------- ### Environment Variables for Cloud Transcoder Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudtranscoder/README_ZH.md These environment variables are required to configure the Agora Cloud Transcoder example project. They include credentials, channel information, and user IDs for input and output streams. ```bash export APP_ID= export BASIC_AUTH_USERNAME= export BASIC_AUTH_PASSWORD= export INPUT_UID_1= export INPUT_UID_2= export INPUT_CHANNEL_NAME= export INPUT_TOKEN_1= export INPUT_TOKEN_2= export UPDATE_INPUT_UID_3= export UPDATE_INPUT_TOKEN_3= export OUTPUT_UID= export OUTPUT_TOKEN= export OUTPUT_CHANNEL_NAME= ``` -------------------------------- ### Environment Variables for CloudRecording Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudrecording/README_ZH.md Configures essential environment variables required to run the Agora Cloud Recording example. These include App ID, Channel Name, User ID, authentication credentials, token, and storage configuration details for cloud storage. ```bash export APP_ID= export CNAME= export USER_ID= export BASIC_AUTH_USERNAME= export BASIC_AUTH_PASSWORD= export TOKEN= export STORAGE_CONFIG_VENDOR= export STORAGE_CONFIG_REGION= export STORAGE_CONFIG_BUCKET= export STORAGE_CONFIG_ACCESS_KEY= export STORAGE_CONFIG_SECRET_KEY= ``` -------------------------------- ### Environment Variables Configuration Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudrecording/README.md Sets up necessary environment variables for the Agora Cloud Recording service. These include application credentials, channel information, user ID, basic authentication, and storage configuration details. ```bash export APP_ID= export CNAME= export USER_ID= export BASIC_AUTH_USERNAME= export BASIC_AUTH_PASSWORD= export TOKEN= export STORAGE_CONFIG_VENDOR= export STORAGE_CONFIG_REGION= export STORAGE_CONFIG_BUCKET= export STORAGE_CONFIG_ACCESS_KEY= export STORAGE_CONFIG_SECRET_KEY= ``` -------------------------------- ### Environment Variable Configuration Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/cloudtranscoder/README.md Sets up necessary environment variables for the CloudTranscoder example. These variables include Agora App ID, Basic Auth credentials, input/output UIDs and channel names, and authentication tokens. ```bash export APP_ID= export BASIC_AUTH_USERNAME= export BASIC_AUTH_PASSWORD= export INPUT_UID_1= export INPUT_UID_2= export INPUT_CHANNEL_NAME= export INPUT_TOKEN_1= export INPUT_TOKEN_2= export UPDATE_INPUT_UID_3= export UPDATE_INPUT_TOKEN_3= export OUTPUT_UID= export OUTPUT_TOKEN= export OUTPUT_CHANNEL_NAME= ``` -------------------------------- ### 开始云端录制 Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README_ZH.md 在获取 Resource ID 后,调用 start 方法开始云端录制。需要提供频道名、用户 UID、Token、Resource ID、录制模式以及详细的录制配置。 ```go startResp, err := cloudRecordingClient.Start(ctx, resp.SuccessRes.ResourceId, mode, &cloudRecordingAPI.StartReqBody{ Cname: cname, Uid: uid, ClientRequest: &cloudRecordingAPI.StartClientRequest{ Token: token, RecordingConfig: &cloudRecordingAPI.RecordingConfig{ ChannelType: 1, StreamTypes: 2, AudioProfile: 2, MaxIdleTime: 30, TranscodingConfig: &cloudRecordingAPI.TranscodingConfig{ Width: 640, Height: 260, FPS: 15, BitRate: 500, MixedVideoLayout: 0, BackgroundColor: "#000000", }, SubscribeAudioUIDs: []string{ "22", "456", }, SubscribeVideoUIDs: []string{ "22", "456", }, }, RecordingFileConfig: &cloudRecordingAPI.RecordingFileConfig{ AvFileType: []string{ "hls", }, }, StorageConfig: &cloudRecordingAPI.StorageConfig{ Vendor: 2, Region: 3, Bucket: "xxx", AccessKey: "xxxx", SecretKey: "xxx", FileNamePrefix: []string{ "xx1", "xx2", }, }, }, }) if err != nil { log.Fatalln(err) } if startResp.IsSuccess() { log.Printf("success:%+v", &startResp.SuccessResponse) } else { log.Printf("failed:%+v", &startResp.ErrResponse) } ``` -------------------------------- ### Start Cloud Transcoding Task Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudtranscoder/README.md Shows how to start a cloud transcoding task by calling the `Create` method after acquiring resources. This method requires a `builderToken` obtained from the `Acquire` method and detailed configuration for audio inputs and outputs, including RTC channel information and audio profiles. ```go createResp, err := cloudTranscoderClient.Create(ctx, tokenName, &cloudTranscoderAPI.CreateReqBody{ Services: &cloudTranscoderAPI.CreateReqServices{ CloudTranscoder: &cloudTranscoderAPI.CloudTranscoderPayload{ ServiceType: "cloudTranscoderV2", Config: &cloudTranscoderAPI.CloudTranscoderConfig{ Transcoder: &cloudTranscoderAPI.CloudTranscoderConfigPayload{ IdleTimeout: 300, AudioInputs: []cloudTranscoderAPI.CloudTranscoderAudioInput{ { Rtc: &cloudTranscoderAPI.CloudTranscoderRtc{ RtcChannel: "test-abc", RtcUID: 123, RtcToken: "xxxxxx", }, }, }, Outputs: []cloudTranscoderAPI.CloudTranscoderOutput{ { Rtc: &cloudTranscoderAPI.CloudTranscoderRtc{ RtcChannel: "test-efg", RtcUID: 456, RtcToken: "xxxxx", }, AudioOption: &cloudTranscoderAPI.CloudTranscoderOutputAudioOption{ ProfileType: "AUDIO_PROFILE_MUSIC_STANDARD", }, }, }, }, }, }, }, }) if err != nil { log.Fatalln(err) } if createResp.IsSuccess() { log.Printf("create success:%+v\n", createResp) } else { log.Printf("create failed:%+v\n", createResp) return } ``` -------------------------------- ### Environment Variable Setup Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README_ZH.md Sets up essential environment variables for the Conversational AI Engine service. These include APP_ID, BASIC_AUTH credentials, and CONVOAI specific tokens and channel information. ```bash export APP_ID= export BASIC_AUTH_USERNAME=<您的基本认证用户名> export BASIC_AUTH_PASSWORD=<您的基本认证密码> export CONVOAI_TOKEN=<您的代理令牌> export CONVOAI_CHANNEL=<您的频道名称> export CONVOAI_AGENT_RTC_UID=<您的代理 RTC UID> ``` -------------------------------- ### Acquire Cloud Recording Resources Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README.md Obtains a Resource ID required before initiating a cloud recording. A Resource ID is unique to a single recording service. This example demonstrates setting up the client and making the acquire call. ```go appId := "xxxx" username := "xxxx" password := "xxxx" credential := auth.NewBasicAuthCredential(username, password) config := &agora.Config{ AppID: appId, Credential: credential, DomainArea: domain.CN, Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), } cloudRecordingClient, err := cloudrecording.NewClient(config) if err != nil { log.Println(err) return } resp, err := cloudRecordingClient.Acquire(context.TODO(), &cloudRecordingAPI.AcquireReqBody{ Cname: "12321", Uid: "43434", ClientRequest: &cloudRecordingAPI.AcquireClientRequest{ Scene: 0, }, }) if err != nil { log.Fatal(err) } if resp.IsSuccess() { log.Printf("resourceId:%s", resp.SuccessRes.ResourceId) } else { log.Printf("resp:%+v", resp) } ``` -------------------------------- ### Create Conversational AI Agent Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/convoai/README_ZH.md Creates a conversational AI agent instance and joins an RTC channel. This involves setting LLM, TTS, and agent-related parameters. The `Join` method is used to establish the agent, with an example using ByteDance TTS. ```go const ( appId = "" cname = "" agentRtcUid = "" username = "" password = "" agentRtcToken = "" llmURL = "" llmAPIKey = "" llmModel = "" ttsBytedanceToken = "" ttsBytedanceAppId = "" ttsBytedanceCluster = "" ttsBytedanceVoiceType = "" ) name := appId + ":" + cname // Start agent joinResp, err := convoaiClient.Join(ctx, name, &req.JoinPropertiesReqBody{ Token: agentRtcToken, Channel: cname, AgentRtcUId: agentRtcUid, RemoteRtcUIds: []string{"*"}, EnableStringUId: agoraUtils.Ptr(false), IdleTimeout: agoraUtils.Ptr(120), LLM: &req.JoinPropertiesCustomLLMBody{ Url: llmURL, APIKey: llmAPIKey, SystemMessages: []map[string]any{ { "role": "system", "content": "You are a helpful chatbot.", }, }, Params: map[string]any{ "model": llmModel, "max_tokens": 1024, }, MaxHistory: agoraUtils.Ptr(30), GreetingMessage: "Hello, how can I help you?", }, TTS: &req.JoinPropertiesTTSBody{ Vendor: req.BytedanceTTSVendor, Params: &req.TTSBytedanceVendorParams{ Token: ttsBytedanceToken, AppId: ttsBytedanceAppId, Cluster: ttsBytedanceCluster, VoiceType: ttsBytedanceVoiceType, SpeedRatio: 1.0, VolumeRatio: 1.0, PitchRatio: 1.0, Emotion: "happy", }, }, }) if err != nil { log.Fatalln(err) } if joinResp.IsSuccess() { log.Printf("Join success:%+v", joinResp) } else { log.Printf("Join failed:%+v", joinResp) } ``` -------------------------------- ### Agora Cloud Recording RESTful API Reference Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README.md Provides details on the Agora Cloud Recording RESTful API endpoints for managing recording sessions. Includes parameters for starting, stopping, and querying recording status, as well as information on response structures and modes. ```APIDOC Stop: Description: Stops an ongoing cloud recording session. Parameters: - cname: Channel name (string) - uid: User ID (string) - resourceId: Cloud recording resource ID (string) - sid: Session ID (string) - mode: Cloud recording mode (string) - clientRequest: Optional client-specific request parameters. - AsyncStop: Boolean, if true, the server stops the recording asynchronously. Response: - Varies based on serverResponseMode. Check documentation for specific structures. Query: Description: Checks the status of a cloud recording session. Parameters: - cname: Channel name (string) - uid: User ID (string) - resourceId: Cloud recording resource ID (string) - sid: Session ID (string) - mode: Cloud recording mode (string) Response: - SuccessResponse: Contains the recording status details. - ServerResponseMode: Indicates the type of recording response (e.g., IndividualRecording, MixRecordingHLS, WebRecording). - IndividualRecordingServerResponse: Details for individual recordings. - MixRecordingHLSServerResponse: Details for HLS mixed recordings. - MixRecordingHLSAndMP4ServerResponse: Details for HLS and MP4 mixed recordings. - WebRecording2CDNServerResponse: Details for web recordings. - ErrResponse: Contains error details if the query fails. ``` -------------------------------- ### Create Conversational Agent with Microsoft TTS Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/convoai/README.md Creates a conversational agent and joins an RTC channel. This example demonstrates configuring the agent with custom LLM parameters and Microsoft Text-to-Speech (TTS) settings, including key, region, voice name, speed, volume, and sample rate. It handles the join response to confirm success or failure. ```go const ( appId = "" cname = "" agentRtcUid = "" username = "" password = "" agentRtcToken = "" llmURL = "" llmAPIKey = "" llmModel = "" tsMicrosoftKey = "" tsMicrosoftRegion = "" tsMicrosoftVoiceName = "" ) // Start agent name := appId + ":" + cname joinResp, err := convoaiClient.Join(context.Background(), name, &req.JoinPropertiesReqBody{ Token: agentRtcToken, Channel: cname, AgentRtcUId: agentRtcUid, RemoteRtcUIds: []string{"*"}, EnableStringUId: agoraUtils.Ptr(false), IdleTimeout: agoraUtils.Ptr(120), LLM: &req.JoinPropertiesCustomLLMBody{ Url: llmURL, APIKey: llmAPIKey, SystemMessages: []map[string]any{ { "role": "system", "content": "You are a helpful chatbot.", }, }, Params: map[string]any{ "model": llmModel, "max_tokens": 1024, }, MaxHistory: agoraUtils.Ptr(30), GreetingMessage: "Hello, how can I help you?", }, TTS: &req.JoinPropertiesTTSBody{ Vendor: req.MicrosoftTTSVendor, Params: &req.TTSMicrosoftVendorParams{ Key: ttsMicrosoftKey, Region: ttsMicrosoftRegion, VoiceName: ttsMicrosoftVoiceName, Speed: 1.0, Volume: 70, SampleRate: 24000, }, }, }) if err != nil { log.Fatalln(err) } if joinResp.IsSuccess() { log.Printf("Join success:%+v", joinResp) } else { log.Printf("Join failed:%+v", joinResp) } ``` -------------------------------- ### Running the Sample Project Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README.md Executes the sample Go project for the Agora Conversational AI service, allowing selection of a TTS vendor and service region. ```go go run main.go --ttsVendor= --serviceRegion=2 ``` -------------------------------- ### Initialize Conversational AI Client Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/convoai/README_ZH.md Initializes the Conversational AI service client with provided configuration including App ID, credentials, region, logger, and service region. This is the first step to interact with the Agora Conversational AI service. ```go const ( appId = "" cname = "" username = "" password = "" ) // Initialize Conversational AI Config config := &convoai.Config{ AppID: appId, Credential: auth.NewBasicAuthCredential(username, password), // Specify the region where the server is located. Options include CN, EU, AP, US. // The client will automatically switch to use the best domain based on the configured region. DomainArea: domain.CN, // Specify the log output level. Options include DebugLevel, InfoLevel, WarningLevel, ErrLevel. // To disable log output, set logger to DiscardLogger. Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), // Specify the service region. Options include ChineseMainlandServiceRegion, GlobalServiceRegion. // ChineseMainlandServiceRegion and GlobalServiceRegion are two different services. ServiceRegion: convoai.ChineseMainlandServiceRegion, } // Initialize the Conversational AI service client convoaiClient, err := convoai.NewClient(config) if err != nil { log.Fatalln(err) } ``` -------------------------------- ### 获取云端录制资源 Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README_ZH.md 调用 acquire 方法获取一个 Resource ID,该 ID 用于一次云端录制服务。需要提供 App ID、Basic Auth 用户名和密码、频道名和用户 UID。 ```go appId := "xxxx" username := "xxxx" password := "xxxx" credential := auth.NewBasicAuthCredential(username, password) config := &agora.Config{ AppID: appId, Credential: credential, DomainArea: domain.CN, Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), } cloudRecordingClient, err := cloudrecording.NewClient(config) if err != nil { log.Println(err) return } resp, err := cloudRecordingClient.Acquire(context.TODO(), &cloudRecordingAPI.AcquireReqBody{ Cname: "12321", Uid: "43434", ClientRequest: &cloudRecordingAPI.AcquireClientRequest{ Scene: 0, }, }) if err != nil { log.Fatal(err) } if resp.IsSuccess() { log.Printf("resourceId:%s", resp.SuccessRes.ResourceId) } else { log.Printf("resp:%+v", resp) } ``` -------------------------------- ### Initialize Conversational AI Engine Client Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/convoai/README.md Initializes the Agora Conversational AI Engine client with provided App ID, credentials, and configuration settings. It allows specifying the server region and log output level. The client is essential for interacting with the Conversational AI service. ```go const ( appId = "" username = "" password = "" ) // Initialize Conversational AI Config config := &convoai.Config{ AppID: appId, Credential: auth.NewBasicAuthCredential(username, password), // Specify the region where the server is located. Options include CN, EU, AP, US. // The client will automatically switch to use the best domain based on the configured region. DomainArea: domain.US, // Specify the log output level. Options include DebugLevel, InfoLevel, WarningLevel, ErrLevel. // To disable log output, set logger to DiscardLogger. Logger: agoraLogger.NewDefaultLogger(agoraLogger.DebugLevel), ServiceRegion: convoai.GlobalServiceRegion, } // Initialize the Conversational AI service client convoaiClient, err := convoai.NewClient(config) if err != nil { log.Fatalln(err) } ``` -------------------------------- ### Agora Cloud Recording RESTful API Reference Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README.md Provides details on the RESTful APIs for Agora's Cloud Recording service. This includes methods for acquiring resources and starting/stopping recordings, along with their required parameters and response structures. ```APIDOC Acquire: Endpoint: POST /v1/apps/{appId}/cloud_recording/resourceid Description: Acquires a Resource ID for cloud recording. Parameters: - appId (path): Your Agora App ID. - Authorization (header): Basic Auth credentials (username:password). Request Body: cname (string): Channel name. uid (string): User ID. clientRequest (object): scene (integer): Recording scene type (e.g., 0 for audio, 1 for video). Response (Success): resourceId (string): The acquired Resource ID. Response (Error): code (integer): Error code. message (string): Error message. Start: Endpoint: POST /v1/apps/{appId}/cloud_recording/resourceid/{resourceId}/start Description: Starts cloud recording for a channel. Parameters: - appId (path): Your Agora App ID. - resourceId (path): The Resource ID obtained from the Acquire call. - Authorization (header): Basic Auth credentials (username:password). Request Body: cname (string): Channel name. uid (string): User ID. clientRequest (object): token (string): Token for the user UID. recordingConfig (object): channelType (integer): Channel type (e.g., 0 for live, 1 for.]. streamTypes (integer): Stream types to record (e.g., 1 for audio, 2 for video, 3 for both). audioProfile (integer): Audio profile settings. maxIdleTime (integer): Maximum idle time before stopping recording. transcodingConfig (object, optional): Configuration for transcoding. width (integer): Video width. height (integer): Video height. fps (integer): Frames per second. bitRate (integer): Video bitrate. mixedVideoLayout (integer): Layout for mixed video. backgroundColor (string): Background color for mixed video. subscribeAudioUIDs (array of strings, optional): UIDs to subscribe to for audio. subscribeVideoUIDs (array of strings, optional): UIDs to subscribe to for video. recordingFileConfig (object): avFileType (array of strings): File types for recording (e.g., ["hls"], ["mp4"]. storageConfig (object): vendor (integer): Cloud storage vendor (e.g., 1 for AWS, 2 for Azure). region (integer): Cloud storage region. bucket (string): Bucket name. accessKey (string): Access key for storage. secretKey (string): Secret key for storage. fileNamePrefix (array of strings): Prefix for recording file names. Response (Success): success (boolean): Indicates success. message (string): Success message. Response (Error): code (integer): Error code. message (string): Error message. Stop: Endpoint: POST /v1/apps/{appId}/cloud_recording/resourceid/{resourceId}/stop Description: Stops an ongoing cloud recording. Parameters: - appId (path): Your Agora App ID. - resourceId (path): The Resource ID of the recording to stop. - Authorization (header): Basic Auth credentials (username:password). Request Body: cname (string): Channel name. uid (string): User ID. Response (Success): success (boolean): Indicates success. message (string): Success message. Response (Error): code (integer): Error code. message (string): Error message. Mode/Update: Endpoint: POST /v1/apps/{appId}/cloud_recording/resourceid/{resourceId}/mode/update Description: Updates the recording mode or configuration. Parameters: - appId (path): Your Agora App ID. - resourceId (path): The Resource ID of the recording to update. - Authorization (header): Basic Auth credentials (username:password). Request Body: cname (string): Channel name. uid (string): User ID. clientRequest (object): recordingConfig (object): Updated recording configuration. recordingFileConfig (object): storageConfig (object): Response (Success): success (boolean): Indicates success. message (string): Success message. Response (Error): code (integer): Error code. message (string): Error message. Query: Endpoint: GET /v1/apps/{appId}/cloud_recording/resourceid/{resourceId}/query Description: Queries the status of a cloud recording. Parameters: - appId (path): Your Agora App ID. - resourceId (path): The Resource ID of the recording to query. - Authorization (header): Basic Auth credentials (username:password). Response (Success): data (object): Recording status details. Response (Error): code (integer): Error code. message (string): Error message. ``` -------------------------------- ### Minimax TTS Configuration Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README_ZH.md Configures environment variables for the Minimax Text-to-Speech (TTS) provider. Requires Group ID, Group Key, and Group Model. ```bash export CONVOAI_TTS_MINIMAX_GROUP_ID= export CONVOAI_TTS_MINIMAX_GROUP_KEY= export CONVOAI_TTS_MINIMAX_GROUP_MODEL= ``` -------------------------------- ### OpenAI TTS Environment Variables Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/examples/convoai/README.md Configures environment variables for the OpenAI Text-to-Speech (TTS) provider, including API key, model, voice, instructions, and speed. ```bash export CONVOAI_TTS_OPENAI_API_KEY= export CONVOAI_TTS_OPENAI_MODEL= export CONVOAI_TTS_OPENAI_VOICE= export CONVOAI_TTS_OPENAI_INSTRUCTIONS= export CONVOAI_TTS_OPENAI_SPEED= ``` -------------------------------- ### 停止云端录制 Source: https://github.com/agoraio-community/agora-rest-client-go/blob/main/services/cloudrecording/README_ZH.md 调用 stop 方法停止云端录制。停止后如需再次录制,需重新获取 Resource ID。需要提供频道名、用户 ID、Resource ID、会话 ID 和录制模式。 ```go stopResp, err := cloudRecordingClient.Stop(ctx, resourceId, sid, mode, &cloudRecordingAPI.cloudRecordingAPI{ Cname: cname, Uid: uid, ClientRequest: &cloudRecordingAPI.StopClientRequest{ AsyncStop: true, }, }) if err != nil { log.Fatalln(err) } if stopResp.IsSuccess() { log.Printf("stop success:%+v", &stopResp.SuccessResponse) } else { log.Fatalf("stop failed:%+v", &stopResp.ErrResponse) } ```