@@ -7,7 +7,9 @@ description: >
7
7
Set up real-time interaction with a Conversational AI agent.
8
8
---
9
9
10
- import MultiCodeBlock , { CodeGroup , CodeItem } from ' @app/mdx-components/MultiCodeBlock' ;
10
+ import Tabs from ' @theme/Tabs' ;
11
+ import TabItem from ' @theme/TabItem' ;
12
+ import CodeBlock from ' @theme/CodeBlock' ;
11
13
12
14
This page describes how to call the <Vpd k = " NAME" /> RESTful APIs to start and stop an AI agent.
13
15
@@ -53,9 +55,9 @@ This section introduces the basic RESTful API requests you use to start and stop
53
55
54
56
Call the ` join ` endpoint to create an agent instance that joins an Agora channel. Pass in the ` channel ` name and ` token ` for agent authentication. To generate your base64-encoded credentials, see [ RESTful authentication] ( ../rest-api/restful-authentication.mdx ) .
55
57
56
- <MultiCodeBlock caption = " Sample request: " >
57
- <CodeGroup label = " Select " >
58
- <CodeItem language = " js " name = " Node. js" >{ ` const fetch = require('node-fetch');\n
58
+ <Tabs groupId = " language " >
59
+ <TabItem value = " node " label = " Node.js " default >
60
+ <CodeBlock language = " js" >{ ` const fetch = require('node-fetch');\n
59
61
const url = "https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/join";\n
60
62
const headers = \{
61
63
"Authorization": "Basic <your_base64_encoded_credentials>",
@@ -106,9 +108,11 @@ fetch(url, \{
106
108
})
107
109
.then(response => response.json())
108
110
.then(json => console.log(json))
109
- .catch(error => console.error("Error:", error)); ` } </CodeItem >
111
+ .catch(error => console.error("Error:", error)); ` } </CodeBlock >
112
+ </TabItem >
110
113
111
- <CodeItem language = " json" name = " curl" >{ ` curl --request POST \\
114
+ <TabItem value = " curl" label = " Curl" >
115
+ <CodeBlock language = " json" >{ ` curl --request POST \\
112
116
--url https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/join \\
113
117
--header 'Authorization: Basic <your_base64_encoded_credentials>' \\
114
118
--header 'Content-Type: application/json' \\
@@ -150,9 +154,11 @@ fetch(url, \{
150
154
}
151
155
}
152
156
}
153
- }' ` } </CodeItem >
157
+ }' ` } </CodeBlock >
158
+ </TabItem >
154
159
155
- <CodeItem language = " python" name = " Python" >{ ` import requests
160
+ <TabItem value = " python" label = " Python" >
161
+ <CodeBlock language = " python" >{ ` import requests
156
162
import json\n
157
163
url = "https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/join"\n
158
164
headers = \{
@@ -198,10 +204,10 @@ data = \{
198
204
}
199
205
}\n
200
206
response = requests.post(url, headers=headers, data=json.dumps(data))
201
- print(response.text) ` } </CodeItem >
207
+ print(response.text) ` } </CodeBlock >
202
208
203
- </CodeGroup >
204
- </MultiCodeBlock >
209
+ </TabItem >
210
+ </Tabs >
205
211
206
212
For complete information on all request parameters, see [ Start a conversational AI agent] ( ../rest-api/join ) .
207
213
@@ -223,9 +229,9 @@ Store the `agent_id` for use in subsequent API calls to [query](../rest-api/quer
223
229
To end the conversation with the AI agent, call the ` leave ` endpoint. This causes the agent to leave the Agora channel.
224
230
225
231
226
- <MultiCodeBlock caption = " Sample request: " >
227
- <CodeGroup label = " Select " >
228
- <CodeItem language = " js " name = " Node. js" >{ ` const url = 'https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/leave';\n
232
+ <Tabs groupId = " language " >
233
+ <TabItem value = " node " label = " Node.js " >
234
+ <CodeBlock language = " js" >{ ` const url = 'https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/leave';\n
229
235
const options = \{
230
236
method: 'POST',
231
237
headers: {
@@ -237,24 +243,27 @@ fetch(url, options)
237
243
.then(res => res.json())
238
244
.then(json => console.log(json))
239
245
.catch(err => console.error(err));
240
- ` } </CodeItem >
246
+ ` } </CodeBlock >
247
+ </TabItem >
241
248
242
- <CodeItem language = " bash" name = " curl" >{ ` curl --request post \\
249
+ <TabItem value = " curl" label = " Curl" >
250
+ <CodeBlock language = " bash" >{ ` curl --request post \\
243
251
--url https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/leave \\
244
- --header 'Authorization: Basic <your_base64_encoded_credentials>' ` } </CodeItem >
252
+ --header 'Authorization: Basic <your_base64_encoded_credentials>' ` } </CodeBlock >
253
+ </TabItem >
245
254
246
- <CodeItem language = " python" name = " Python" >{ ` import requests\n
255
+ <TabItem value = " python" label = " Python" >
256
+ <CodeBlock language = " python" >{ ` import requests\n
247
257
url = "https://api.agora.io/api/conversational-ai-agent/v2/projects/:appid/agents/:agentId/leave"\n
248
258
headers = \{
249
259
"Authorization": "Basic <your_base64_encoded_credentials>",
250
260
"Content-Type": "application/json"
251
261
}\n
252
262
response = requests.post(url, headers=headers)
253
263
print(response.text)
254
- ` } </CodeItem >
255
-
256
- </CodeGroup >
257
- </MultiCodeBlock >
264
+ ` } </CodeBlock >
265
+ </TabItem >
266
+ </Tabs >
258
267
259
268
If the request is successful, the server responds with a ` 200 OK ` status and an empty JSON object.
260
269
0 commit comments