Sends a message to an existing chat session. The AI agent will process the message and generate an appropriate response based on the conversation context.
curl -X POST https://api.nexusgpt.io/api/public/thread/550e8400-e29b-41d4-a716-446655440000/messages \ -H "Content-Type: application/json" \ -H "api-key: YOUR_API_KEY" \ -d '{"content": "Can you help me track my order #12345?"}'
const axios = require('axios');async function sendMessage(sessionId, message) { try { const response = await axios.post( `https://api.nexusgpt.io/api/public/thread/${sessionId}/messages`, { content: message }, { headers: { 'Content-Type': 'application/json', 'api-key': process.env.NEXUS_API_KEY } } ); console.log('Message sent successfully'); // Wait a moment for the agent to process await new Promise(resolve => setTimeout(resolve, 1500)); // Fetch the latest messages to see the response return await getMessages(sessionId); } catch (error) { console.error('Error sending message:', error.response?.data); throw error; }}// Send a message to an existing sessionawait sendMessage('550e8400-e29b-41d4-a716-446655440000', 'Can you help me track my order #12345?');
import osimport requestsimport timedef send_message(session_id, message): """Send a message to an existing session""" url = f"https://api.nexusgpt.io/api/public/thread/{session_id}/messages" headers = { "Content-Type": "application/json", "api-key": os.environ.get("NEXUS_API_KEY") } data = { "content": message } try: response = requests.post(url, json=data, headers=headers) response.raise_for_status() print("Message sent successfully") # Wait for agent to process time.sleep(1.5) # Fetch latest messages to see response return get_messages(session_id) except requests.exceptions.RequestException as e: print(f"Error sending message: {e}") if hasattr(e, 'response'): print(f"Response: {e.response.text}") raise# Send a message to an existing sessionsend_message('550e8400-e29b-41d4-a716-446655440000', 'Can you help me track my order #12345?')
package mainimport ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" "time")type SendMessageRequest struct { Content string `json:"content"`}type SendMessageResponse struct { Success bool `json:"success"`}func sendMessage(sessionID, message string) error { url := fmt.Sprintf("https://api.nexusgpt.io/api/public/thread/%s/messages", sessionID) requestBody := SendMessageRequest{ Content: message, } jsonData, err := json.Marshal(requestBody) if err != nil { return err } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") req.Header.Set("api-key", os.Getenv("NEXUS_API_KEY")) client := &http.Client{} resp, err := client.Do(req) if err != nil { return err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return err } if resp.StatusCode != http.StatusOK { return fmt.Errorf("API error: %s", string(body)) } var result SendMessageResponse if err := json.Unmarshal(body, &result); err != nil { return err } if result.Success { fmt.Println("Message sent successfully") // Wait for agent to process time.Sleep(1500 * time.Millisecond) // Fetch messages to see response // getMessages(sessionID) } return nil}
async function handleConversation(sessionId) { // Initial greeting await sendMessage(sessionId, "Hello!"); // Follow-up with context await sendMessage(sessionId, "I need help with order #12345"); // Provide additional details await sendMessage(sessionId, "It was supposed to arrive yesterday");}