"use strict";(self.webpackChunknewoaks_help=self.webpackChunknewoaks_help||[]).push([[4396],{2002:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>d,default:()=>p,frontMatter:()=>h,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"api/chat/message-a-chatbot","title":"Message a Chatbot","description":"The  API enables you to generate an AI response based on the user\'s question by sending a POST request to the /chat/Chat/ClientAsk endpoint.","source":"@site/developer/api/003.chat/108.message-a-chatbot.md","sourceDirName":"api/003.chat","slug":"/api/chat/message-a-chatbot","permalink":"/guides/developer/api/chat/message-a-chatbot","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":108,"frontMatter":{"sidebar_position":108},"sidebar":"sidebar","previous":{"title":"Create Chat Session","permalink":"/guides/developer/api/chat/create-session"},"next":{"title":"Real Estate","permalink":"/guides/developer/category/real-estate"}}');var o=s(4848),r=s(8453),a=s(767),i=s(8175);const h={sidebar_position:108},d="Message a Chatbot",l={},c=[{value:"Endpoint",id:"endpoint",level:2},{value:"Request Headers",id:"request-headers",level:2},{value:"Request Body",id:"request-body",level:2},{value:"Example Request",id:"example-request",level:2},{value:"Response",id:"response",level:2},{value:"Not using the return format of the stream:",id:"not-using-the-return-format-of-the-stream",level:3},{value:"Using the return format of the stream:",id:"using-the-return-format-of-the-stream",level:3},{value:"Error Handling",id:"error-handling",level:2}];function u(e){const t={code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"message-a-chatbot",children:"Message a Chatbot"})}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(i.A,{})," API enables you to generate an AI response based on the user's question by sending a ",(0,o.jsx)(t.code,{children:"POST"})," request to the ",(0,o.jsx)(t.code,{children:"/chat/Chat/ClientAsk"})," endpoint."]}),"\n",(0,o.jsx)(t.h2,{id:"endpoint",children:"Endpoint"}),"\n",(0,o.jsx)(a.TM,{path:"/chat/Chat/ClientAsk"}),"\n",(0,o.jsx)(t.h2,{id:"request-headers",children:"Request Headers"}),"\n",(0,o.jsx)(a.iW,{}),"\n",(0,o.jsx)(t.h2,{id:"request-body",children:"Request Body"}),"\n",(0,o.jsx)(a.VQ,{requestBody:{sessionID:123,content:"hello",chatAskType:null,stream:!1,fileIds:null},requestBodyParams:{sessionID:"integer, required - The session ID obtained from the Create Chat Session API",content:"string, required - The question or message from the user.If chatAskType is [Image,Audio,Video], content can be empty.",stream:"boolean, optional - Whether to stream back partial progress. Defaults to false.",chatAskType:"string, optional - The optional values are: Text, Audio,Image,Video. This field can be left null, with the default value being Text.",fileIds:"List(integer), optional - It is an integer array, valid only when chatAskType is set to [Image,Video,Audio].In image mode, multiple images are supported, while in [video,Audio] mode, only a single [video,audio] is allowed.Audio is only supported in WAV format.Video is only supported in [MP4,MKV,AVI,FLV,MPEG] format.Image is only supported in [PNG (.png),JPEG (.jpeg and .jpg),WEBP (.webp),Non-animated GIF (.gif)] format.Size limits:Up to 20MB per image;Up to 100MB per video;"}}),"\n",(0,o.jsx)(t.h2,{id:"example-request",children:"Example Request"}),"\n",(0,o.jsx)(a.r3,{path:"/chat/Chat/ClientAsk",requestBody:{sessionID:123,content:"hello",stream:!1}}),"\n",(0,o.jsx)(t.h2,{id:"response",children:"Response"}),"\n",(0,o.jsx)(t.h3,{id:"not-using-the-return-format-of-the-stream",children:"Not using the return format of the stream:"}),"\n",(0,o.jsx)(a.zV,{responseExample:{Data:{messageid:375561,content:"Hello! How can I assist you today?",totalToken:4337,noAnswer:!1},Version:"1.0.0",Success:!0,Code:200,Message:""},responseComments:{"Data.messageid":"integer - Unique identifier for the AI's response message","Data.content":"string - The AI's response message","Data.totalToken":"integer - The total amount of tokens consumed for this answer","Data.noAnswer":"boolean - Indicates if the AI was unable to provide an answer",Version:"string - API version",Success:"boolean - Operation success status",Code:"integer - HTTP status code",Message:"string - Error message if any"}}),"\n",(0,o.jsx)(t.h3,{id:"using-the-return-format-of-the-stream",children:"Using the return format of the stream:"}),"\n",(0,o.jsx)(t.p,{children:"Response Header:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'{\n  "Content-Type": "text/event-stream"  \n}\n'})}),"\n",(0,o.jsx)(t.p,{children:"Response Body:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-json",children:'// The AI \u200b\u200bresponse.\n{"content":"\\n"}\n{"content":"Hello"}\n{"content":"!"}\n{"content":" How"}\n{"content":" can"}\n{"content":" I"}\n{"content":" assist"}\n{"content":" you"}\n{"content":"?"}\n// QuestionID is the message ID of the request, AnswerID is the message ID of the response, Answer is the complete answer of the AI, and TotalToken is the number of tokens consumed.\n{"QuestionID":10495005,"AnswerID":10495006,"Answer":"\\nHello! How can I assist you?","TotalToken":4994}\n'})}),"\n",(0,o.jsx)(t.h2,{id:"error-handling",children:"Error Handling"}),"\n",(0,o.jsx)(a.NH,{})]})}function p(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(u,{...e})}):u(e)}},767:(e,t,s)=>{s.d(t,{Ay:()=>m,NH:()=>p,TM:()=>h,VQ:()=>l,iW:()=>d,r3:()=>c,zV:()=>u});s(6540);var n=s(3532),o=s(8069),r=s(9303),a=s(4848);const i=function(e,t){void 0===t&&(t={});const s=JSON.stringify(e,null,2).split("\n"),n=[];return s.forEach((e=>{const s=e.match(/"([^"]+)":/);if(s&&t[s[1]]){const o=e.match(/^\s*/)?.[0]||"";n.push(`${o}// ${t[s[1]]}`)}n.push(e)})),n.join("\n")},h=e=>{let{path:t,method:s="POST"}=e;const o=(0,n.r)()(t)||`https://usapi.hottask.com${t}`;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Request URL:"})," ",o]}),(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Method:"})," ",s]})]})},d=e=>{let{headers:t={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"},headersDescription:s={Authorization:"string, required - The secret key for authenticating the API request","Content-Type":"string, required - The content type of the request payload (must be application/json)"}}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The API request must include the following headers:"}),(0,a.jsx)("ul",{children:Object.entries(t).map((e=>{let[t,n]=e;return(0,a.jsxs)("li",{children:[(0,a.jsxs)("code",{children:[t,": ",n]})," - ",s[t]]},t)}))})]})},l=e=>{let{requestBody:t,requestBodyParams:s,addCommentsToJson:n=i}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The request body should contain the following parameters:"}),(0,a.jsx)(o.A,{language:"json",children:n(t,s)}),(0,a.jsx)("ul",{children:Object.entries(s).map((e=>{let[t,s]=e;return(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:t})," - ",s]},t)}))})]})},c=e=>{let{method:t="POST",path:s,requestBody:i,headers:h={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"}}=e;const d=(0,n.r)()(s),l="undefined"==typeof window?"usapi.hottask.com":new URL(d||`https://usapi.hottask.com${s}`).host,c={javascript:`const res = await fetch('${d||`https://usapi.hottask.com${s}`}', {\n  method: '${t}',\n  headers: ${JSON.stringify(h,null,2)},\n  body: JSON.stringify(${JSON.stringify(i,null,2)})\n});\n\nconst data = await res.json();\nconsole.log(data);`,python:`import requests\nimport json\n\nurl = '${d||`https://usapi.hottask.com${s}`}'\nheaders = ${JSON.stringify(h,null,4)}\ndata = ${JSON.stringify(i,null,2)}\n\nresponse = requests.${t.toLowerCase()}(url, headers=headers, json=data)\ndata = response.json()\nprint(data)`,bash:`curl '${d||`https://usapi.hottask.com${s}`}' \\\n  -X ${t} \\\n${Object.entries(h).map((e=>{let[t,s]=e;return`  -H '${t}: ${s}' \\`})).join("\n")}\n  -d '${JSON.stringify(i)}'`,http:`${t} ${s} HTTP/1.1\nHost: ${l}\n${Object.entries(h).map((e=>{let[t,s]=e;return`${t}: ${s}`})).join("\n")}\n\n${JSON.stringify(i,null,2)}`};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.A,{as:"h3",children:"JavaScript (Fetch API)"}),(0,a.jsx)(o.A,{language:"javascript",children:c.javascript}),(0,a.jsx)(r.A,{as:"h3",children:"Python (Requests Library)"}),(0,a.jsx)(o.A,{language:"python",children:c.python}),(0,a.jsx)(r.A,{as:"h3",children:"cURL"}),(0,a.jsx)(o.A,{language:"bash",children:c.bash}),(0,a.jsx)(r.A,{as:"h3",children:"HTTP Request"}),(0,a.jsx)(o.A,{language:"http",children:c.http})]})},u=e=>{let{responseExample:t,responseComments:s,addCommentsToJson:n=i}=e;const r={...t,Version:"1.0.0",Success:!0,Code:200,Message:""},h={...s,Version:"string - API version",Success:"boolean - Operation success status",Code:"integer - HTTP status code",Message:"string - Error message if any"};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The API response will be a JSON object with the following structure:"}),(0,a.jsx)(o.A,{language:"json",children:n(r,h)})]})},p=e=>{let{errorHandling:t="If the request fails, you should:\n1. Check the HTTP status code for network-level errors\n2. Examine the `Code` and `Message` fields in the response for business-level errors\n3. The `Message` field will contain detailed error information"}=e;return(0,a.jsx)("div",{style:{whiteSpace:"pre-line"},children:t})};function m(e){let{title:t,path:s,method:o="POST",description:r="",requestBody:m={timeZone:"Asia/Shanghai",type:0},requestBodyDescription:g={timeZone:"The time zone of the chatbot. The standard time zone format: e.g., Asia/Shanghai or America/New_York.",type:"Create a generic chatbot with a fixed value of 0"},requestBodyComments:f={timeZone:"string, required",type:"integer, required"},responseExample:j={Data:"3254a9d0424c4806b9ea3d0763xxxxxx",Version:"1.0.0",Success:!0,Code:200,Message:""},responseComments:x={Data:"chatbot id"},headers:y={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"},headersDescription:w={Authorization:"The secret key for authenticating the API request.","Content-Type":"The content type of the request payload."},errorHandling:T="If it's an HTTP network error, you should check the `HTTP status code`. If it's a business exception, you need to examine the `Code` and `Message` fields, which will provide the error details."}=e;const A=(0,n.r)()(s),b="undefined"==typeof window?"usapi.hottask.com":new URL(A||`https://usapi.hottask.com${s}`).host;JSON.stringify(y,null,2),i(m,f),JSON.stringify(y,null,4),i(m,f),o.toLowerCase(),Object.entries(y).map((e=>{let[t,s]=e;return`  -H '${t}: ${s}' \\`})).join("\n"),JSON.stringify(m),Object.entries(y).map((e=>{let[t,s]=e;return`${t}: ${s}`})).join("\n"),i(m,f);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(h,{path:s,method:o}),(0,a.jsx)(d,{headers:y,headersDescription:w}),(0,a.jsx)(l,{requestBody:m,requestBodyParams:g,addCommentsToJson:i}),(0,a.jsx)(c,{method:o,path:s,requestBody:m,headers:y}),(0,a.jsx)(u,{responseExample:j,responseComments:x,addCommentsToJson:i}),(0,a.jsx)(p,{errorHandling:T})]})}},8175:(e,t,s)=>{s.d(t,{A:()=>r});s(6540);var n=s(5872),o=s(4848);function r(){let e=(0,n.K)()();return["newoaks.ai","www.newoaks.ai","eu.newoaks.ai"].includes(e)&&(e="NewOaks AI"),"appointify.ai"===e&&(e="Appointify AI"),(0,o.jsx)("code",{children:e})}},3532:(e,t,s)=>{function n(){return function(e){if("undefined"==typeof window)return"";const t=window.location.hostname;let s="";return s="www.newoaks.ai"==t||"newoaks.ai"==t?"https://usapi.hottask.com":"eu.newoaks.ai"==t?"https://euapi.hottask.com":`https://${t}`,e?`${s}${e.startsWith("/")?e:`/${e}`}`:s}}s.d(t,{r:()=>n})},5872:(e,t,s)=>{function n(){return function(){return"undefined"==typeof window?"":window.location.hostname}}s.d(t,{K:()=>n})}}]);