Get your first AI bot up and running in under 10 minutes. This tutorial will walk you through the essential steps to integrate AI Nexus Pro into your application.
Follow these four simple steps to get your AI bot running in minutes.
Set up the AI Nexus Pro client with your API key
Send your first message to the AI chatbot
Process and display the AI response
Try the voice bot functionality
Copy and paste these examples to get started quickly with your preferred language.
// 1. Initialize the client
import { AINexusClient } from '@ainexuspro/sdk';
const client = new AINexusClient({
apiKey: process.env.AINEXUS_API_KEY,
environment: 'production'
});
// 2. Send your first message
async function sendMessage() {
try {
const response = await client.chat.send({
message: 'Hello! How can you help me today?',
sessionId: 'user_123',
context: {
userId: 'user_456',
timestamp: new Date().toISOString()
}
});
console.log('AI Response:', response.reply);
return response.reply;
} catch (error) {
console.error('Error:', error);
}
}
// 3. Handle the response
sendMessage().then(reply => {
// Display the AI response to your user
document.getElementById('chat-output').textContent = reply;
});
# 1. Initialize the client
from ainexuspro import AINexusClient
import os
client = AINexusClient(
api_key=os.getenv('AINEXUS_API_KEY'),
environment='production'
)
# 2. Send your first message
async def send_message():
try:
response = await client.chat.send(
message="Hello! How can you help me today?",
session_id="user_123",
context={
"user_id": "user_456",
"timestamp": "2024-01-15T10:30:00Z"
}
)
print('AI Response:', response.reply)
return response.reply
except Exception as error:
print('Error:', error)
# 3. Handle the response
reply = await send_message()
# Display the AI response to your user
print(f"AI says: {reply}")
// React component example
import React, { useState } from 'react';
import { AINexusClient } from '@ainexuspro/sdk';
const ChatBot = () => {
const [message, setMessage] = useState('');
const [response, setResponse] = useState('');
const [loading, setLoading] = useState(false);
const client = new AINexusClient({
apiKey: process.env.REACT_APP_AINEXUS_API_KEY,
environment: 'production'
});
const sendMessage = async () => {
setLoading(true);
try {
const result = await client.chat.send({
message,
sessionId: 'user_123'
});
setResponse(result.reply);
} catch (error) {
console.error('Error:', error);
} finally {
setLoading(false);
}
};
return (
<div className="chat-container">
<input
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder="Type your message..."
/>
<button onClick={sendMessage} disabled={loading}>
{loading ? 'Sending...' : 'Send'}
</button>
{response && <div className="response">{response}</div>}
</div>
);
};
Add voice capabilities to your application with our voice bot API.
Start a voice session and handle speech input/output
// Voice Bot Integration
async function startVoiceSession() {
try {
const session = await client.voice.start({
language: 'en-US',
voiceModel: 'nova',
sessionId: 'voice_session_123'
});
console.log('Voice session started:', session.sessionId);
// Handle voice input/output
session.on('speech', (transcript) => {
console.log('User said:', transcript);
});
session.on('response', (audioData) => {
// Play the AI response audio
playAudio(audioData);
});
} catch (error) {
console.error('Voice session error:', error);
}
}
You've successfully set up your first AI bot! Now let's explore more advanced features.
Ask me anything about this page