Integrate an AI agent via code snippet
You can quickly test an AI agent by using a trial token generated in the console, without deploying a server.
This method is for testing only and is not intended for production use, as it may expose the shareToken.
Generate a trial token
Go to the AI Agents page, and select the AI agent to test. If you do not have an AI agent, see Create and manage AI agents to create one.
Click QR Code for Demo and select an expiration time.
Copy the generated trial token.
The QR Code for Demo dialog box displays QR codes for app and web demos, the web demo URL, the trial token, and the expiration time. Click the copy icon next to a field to copy its value.
Integrate the AI agent
Web
Integration code
Add the following code to the <body> section of your webpage.
<script src="https://g.alicdn.com/apsara-media-aui/amaui-web-aicall/2.5.0/aicall-ui.js"></script>
<script>
new ARTCAICallUI({
userId: '123', // The ID for the user joining the RTC channel. Use the logged-in user ID from your business system.
root: document.getElementById('root'), // The root DOM element for UI rendering. The UI will fill this element.
shareToken: 'xxxx', // The trial token copied from the console.
}).render();
</script>Android
Download and integrate source code
To download the source code, go to the GitHub repository.
Import AUIAICall: In Android Studio, go to File > New > Import Module and select the downloaded repository folder.
Modify the third-party library dependencies in the build.gradle file.
dependencies { implementation 'androidx.appcompat:appcompat:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.google.android.material:material:x.x.x' // Change x.x.x to the version compatible with your project androidTestImplementation 'androidx.test.espresso:espresso-core:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.aliyun.aio:AliVCSDK_ARTC:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.aliyun.auikits.android:ARTCAICallKit:x.x.x' implementation 'com.alivc.live.component:PluginAEC:2.0.0' }NoteLatest ARTC SDK version: 7.10.0;
Latest AICallKit SDK version: 2.11.0.
Wait until the synchronization is complete.
Integration code
Context currentActivity = AUIAICallEntranceActivity.this;
// The ID for the user joining the RTC channel. Use the logged-in user ID from your business system.
String loginUserId = "123";
// The trial token copied from the console.
String shareToken = "xxxxx";
ARTCAICallController.launchCallActivity(currentActivity, shareToken, loginUserId, "");iOS
Download and integrate source code
To download the source code, go to the GitHub repository.
After you download the source code from the repository, copy the iOS folder to the code directory of your app and rename the folder AUIAICall. Make sure that the folder is placed at the same directory level as your Podfile. You can delete the Example and AICallKit directories.
Modify the Podfile to import the following components:
AliVCSDK_ARTC: The audio and video client software development kit (SDK) for real-time interaction. You can also use AliVCSDK_Standard or AliVCSDK_InteractiveLive. For more information about integration, see Integrate the SDK for iOS.
ARTCAICallKit: The SDK for the Real-time Conversational AI call scenario.
AUIFoundation: The basic UI components.
AUIAICall: The source code of the UI components for the AI call scenario.
# iOS 11.0 or later is required. platform :ios, '11.0' target 'Your app target' do # Integrate a suitable audio and video client SDK based on your business scenario. AliVCSDK_ARTC, AliVCSDK_Standard, and AliVCSDK_InteractiveLive are supported. pod 'AliVCSDK_ARTC', '~> 7.5.0' # The SDK for the Real-time Conversational AI call scenario. pod 'ARTCAICallKit', '~> 2.8.0' # The source code of the basic UI components. pod 'AUIFoundation', :path => "./AUIAICall/AUIBaseKits/AUIFoundation/", :modular_headers => true # The source code of the UI components for the AI call scenario. pod 'AUIAICall', :path => "./AUIAICall/" endNoteLatest ARTC SDK version: 7.10.0;
Latest AICallKit SDK version: 2.11.0.
Run the
pod install --repo-updatecommand.Complete the integration.
Integration code
import AUIFoundation
import AUIAICall
// Starts a call with the AI agent. Add this code to a button's click event handler.
AUIAICallManager.defaultManager.checkDeviceAuth(agentType: .VisionAgent) {
let topVC = viewController ?? UIViewController.av_top()
let controller = AUIAICallStandardController(userId: "123") // userId: The ID for the user joining the RTC channel. Use the logged-in user ID from your business system.
controller.agentShareInfo = "xxxxx" // The trial token copied from the console.
let vc = AUIAICallViewController(controller)
vc.enableVoiceprintSwitch = false
topVC.av_presentFullScreenViewController(vc, animated: true)
}