API • किसी भी ऐप में इंटीग्रेशन

Chatbot API Integration

WebChatAgent को desktop apps, terminals और internal tools में REST API से जोड़ें — और real live chat के लिए WebSocket पर स्विच करें।

Developers और product teams के लिए

Chat को अपनी app में लाएँ,
सिर्फ website पर नहीं।

हर जगह browser नहीं होता। हमारी Chatbot API से आप conversational UX को सीधे अपने software में बनाते हैं — desktop clients, CLI tools और internal portals तक।

Chatbot API कौन-सी समस्याएँ हल करती है?

Chat integration की आम चुनौतियाँ — और API उन्हें कैसे आसान बनाती है।

Website widget हमेशा फिट नहीं होता

Desktop apps, internal tools या terminals को native integration चाहिए — embedded website widget नहीं।

Chat experience inconsistent हो जाती है

API के बिना chat एक special-case बन जाता है। Dedicated endpoints के साथ आप UX को अपने flows और UI में consistent रखते हैं।

Live chat के लिए real-time जरूरी है

Human takeover में real-time matters: status, messages और files तुरंत पहुँचने चाहिए — WebSocket इसके लिए सही है।

API इन समस्याओं को कैसे हल करती है?

Bot chat के लिए REST से शुरू करें — और जरूरत पर live chat के लिए WebSocket अपनाएँ।

हर frontend के लिए REST API

/api/chat पर POST करके messages भेजें और reply को अपनी UI में दिखाएँ। Desktop, mobile, backoffice और CLI के लिए ideal।

Live Chat के लिए WebSocket (human takeover)

जब mode human हो जाए, WebSocket से connect करें और messages real-time में send/receive करें — session guard के साथ।

Code examples

Minutes में शुरू करें: quick tests के लिए cURL, production integrations के लिए JavaScript।

REST API (cURL)
Fast testing — terminal, CI या debugging के लिए।
# 1) First request (no session id). Use -i to see response headers.
curl -i -X POST https://webchatagent.com/api/chat \
  -H "Content-Type: application/json" \
  -d '{
  "message": "Hello, how can you help me?",
  "chatbotId": "<your-chatbot-id>"
  }'

# 2) Reuse the X-Chat-Session-Id from the response header for the conversation.
curl -X POST https://webchatagent.com/api/chat \
  -H "Content-Type: application/json" \
  -H "X-Chat-Session-Id: <session-id-from-response>" \
  -d '{
  "message": "Continue the conversation.",
  "chatbotId": "<your-chatbot-id>"
  }'
REST API (JavaScript)
fetch() के साथ desktop/web apps में integration।
async function sendChatMessage({ baseUrl, chatbotId, message, sessionId }) {
  const res = await fetch(`${baseUrl}/api/chat`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Chat-Session-Id': sessionId || ''
    },
    body: JSON.stringify({ message, chatbotId })
  });

  const nextSessionId = res.headers.get('X-Chat-Session-Id') || sessionId || '';
  if (!res.ok) throw new Error(await res.text());
  const data = await res.json();
  // data: { reply, sources, mode, status }
  // If mode === 'human' and status === 'waiting' or 'open', switch to WebSocket
  if (data.mode === 'human' && (data.status === 'waiting' || data.status === 'open')) {
    // Switch to WebSocket for live chat
    connectToLiveChat(nextSessionId, chatbotId);
  }
  return { data, sessionId: nextSessionId };
}

Session handling: अगर आप X-Chat-Session-Id नहीं भेजते, server नई session बनाता है और session id को response header में लौटाता है। इसे store करें और next requests में भेजें।

Live chat switch पर response example: [ "reply": "...", "sources": [], "mode": "human", "status": "waiting" ] — फिर WebSocket पर switch करें।

Live chat

Live Chat में क्या ध्यान रखें

Live Chat WebSocket पर चलता है। Connect के बाद chatbotId + sessionId से join करें और messages को client:message के रूप में भेजें। केवल current session के events handle करें।

WebSocket connect + join
Start: connect करें, session join करें, फिर messages भेजें।
// Use the same base URL as your REST calls (WebChatAgent domain).
const ws = new WebSocket('wss://webchatagent.com/api/livechat');
ws.onopen = () => {
  ws.send(JSON.stringify({
    type: 'client:join',
    chatbotId: '<your-chatbot-id>',
    sessionId: '<your-session-id>',
    as: 'user'
  }));
};

function sendLiveChatMessage(text) {
  ws.send(JSON.stringify({
    type: 'client:message',
    chatbotId: '<your-chatbot-id>',
    sessionId: '<your-session-id>',
    sender: 'user',
    content: text
  }));
}

ws.onmessage = (event) => {
  const data = JSON.parse(event.data || '{}');
  // data.type === 'livechat:message'
  // data.sessionId guard recommended (handle only current session)
};
REST बनाम WebSocket कब?
Bot chat के लिए REST perfect है। Human takeover active होते ही WebSocket required है।

Bot mode में REST (/api/chat) use करें।

Response check करें: अगर mode='human' और status='waiting' या 'open' मिले, WebSocket (/api/livechat) पर switch करें।

Session guard लगाएँ: बिना sessionId या अलग sessionId वाले events ignore करें।

Typical use cases

Examples: teams API से support और workflows को सीधे अपने software में embed करते हैं।

Desktop app support

In-app help, troubleshooting और onboarding — browser context-switch के बिना।

Terminal / CLI assistant

Terminal में answers और steps — DevOps, IT और internal tooling के लिए।

Internal portals & backoffice

Employees के लिए self-service: policies, processes और knowledge — intranet में ही।

Escalation to live chat

Bot से automate करें — और जरूरत पर human को handover करें (WebSocket)।

Chat को वहीं embed करें जहाँ आपके users हैं।

REST से शुरू करें और जरूरत पर live chat जोड़ें। Production-ready integrations के लिए बनाया गया: fast, stable और maintainable।

Account बनाएँ