"use strict";(self.webpackChunknewoaks_help=self.webpackChunknewoaks_help||[]).push([[158],{4576:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>l,contentTitle:()=>h,default:()=>p,frontMatter:()=>d,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"api/send-twilio-message","title":"Send Twilio Message","description":"The API provides functionality to send messages via Twilio by sending a POST request to the /chat/Chatbot/SendTwilioMessage endpoint.","source":"@site/developer/api/110.send-twilio-message.md","sourceDirName":"api","slug":"/api/send-twilio-message","permalink":"/guides/developer/api/send-twilio-message","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":110,"frontMatter":{"sidebar_position":110},"sidebar":"sidebar","previous":{"title":"Lead/Appointment Data API","permalink":"/guides/developer/api/lead"},"next":{"title":"Get Message Credits Usage","permalink":"/guides/developer/api/get-message-credits-usage"}}');var r=t(4848),i=t(8453),o=t(767),a=(t(9357),t(8175));const d={sidebar_position:110},h="Send Twilio Message",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:"Error Handling",id:"error-handling",level:2}];function u(e){const s={code:"code",h1:"h1",h2:"h2",header:"header",p:"p",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.header,{children:(0,r.jsx)(s.h1,{id:"send-twilio-message",children:"Send Twilio Message"})}),"\n",(0,r.jsxs)(s.p,{children:["The ",(0,r.jsx)(a.A,{})," API provides functionality to send messages via Twilio by sending a ",(0,r.jsx)(s.code,{children:"POST"})," request to the ",(0,r.jsx)(s.code,{children:"/chat/Chatbot/SendTwilioMessage"})," endpoint."]}),"\n",(0,r.jsx)(s.h2,{id:"endpoint",children:"Endpoint"}),"\n",(0,r.jsx)(o.TM,{path:"/chat/Chatbot/SendTwilioMessage"}),"\n",(0,r.jsx)(s.h2,{id:"request-headers",children:"Request Headers"}),"\n",(0,r.jsx)(o.iW,{}),"\n",(0,r.jsx)(s.h2,{id:"request-body",children:"Request Body"}),"\n",(0,r.jsx)(o.VQ,{requestBody:{SerialNumber:"3254a9d0424c4806b9ea3d0763xxxxxx",ToPhoneNumber:"+1234567890",Message:"Hello!"},requestBodyParams:{SerialNumber:"string, required - The ID of the chatbot (found on the chatbot settings -> general -> chatbot ID)",ToPhoneNumber:"string, required - Target phone number to send the message to",Message:"string, required - Content of the message to be sent"}}),"\n",(0,r.jsx)(s.h2,{id:"example-request",children:"Example Request"}),"\n",(0,r.jsx)(o.r3,{path:"/chat/Chatbot/SendTwilioMessage",requestBody:{SerialNumber:"3254a9d0424c4806b9ea3d0763xxxxxx",ToPhoneNumber:"+1234567890",Message:"Hello!"}}),"\n",(0,r.jsx)(s.h2,{id:"response",children:"Response"}),"\n",(0,r.jsx)(o.zV,{responseExample:{Data:{Status:"True",Message:"test",SessionID:123123123123}},responseComments:{Data:"object - The response data","Data.Status":"string - Status of the message sending operation","Data.Message":"string - Response message","Data.SessionID":"integer - Session identifier"}}),"\n",(0,r.jsx)(s.h2,{id:"error-handling",children:"Error Handling"}),"\n",(0,r.jsx)(o.NH,{})]})}function p(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(u,{...e})}):u(e)}},767:(e,s,t)=>{t.d(s,{Ay:()=>m,NH:()=>p,TM:()=>d,VQ:()=>l,iW:()=>h,r3:()=>c,zV:()=>u});t(6540);var n=t(3532),r=t(8069),i=t(9303),o=t(4848);const a=function(e,s){void 0===s&&(s={});const t=JSON.stringify(e,null,2).split("\n"),n=[];return t.forEach((e=>{const t=e.match(/"([^"]+)":/);if(t&&s[t[1]]){const r=e.match(/^\s*/)?.[0]||"";n.push(`${r}// ${s[t[1]]}`)}n.push(e)})),n.join("\n")},d=e=>{let{path:s,method:t="POST"}=e;const r=(0,n.r)()(s)||`https://usapi.hottask.com${s}`;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("p",{children:[(0,o.jsx)("strong",{children:"Request URL:"})," ",r]}),(0,o.jsxs)("p",{children:[(0,o.jsx)("strong",{children:"Method:"})," ",t]})]})},h=e=>{let{headers:s={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"},headersDescription:t={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,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{children:"The API request must include the following headers:"}),(0,o.jsx)("ul",{children:Object.entries(s).map((e=>{let[s,n]=e;return(0,o.jsxs)("li",{children:[(0,o.jsxs)("code",{children:[s,": ",n]})," - ",t[s]]},s)}))})]})},l=e=>{let{requestBody:s,requestBodyParams:t,addCommentsToJson:n=a}=e;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{children:"The request body should contain the following parameters:"}),(0,o.jsx)(r.A,{language:"json",children:n(s,t)}),(0,o.jsx)("ul",{children:Object.entries(t).map((e=>{let[s,t]=e;return(0,o.jsxs)("li",{children:[(0,o.jsx)("code",{children:s})," - ",t]},s)}))})]})},c=e=>{let{method:s="POST",path:t,requestBody:a,headers:d={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"}}=e;const h=(0,n.r)()(t),l="undefined"==typeof window?"usapi.hottask.com":new URL(h||`https://usapi.hottask.com${t}`).host,c={javascript:`const res = await fetch('${h||`https://usapi.hottask.com${t}`}', {\n method: '${s}',\n headers: ${JSON.stringify(d,null,2)},\n body: JSON.stringify(${JSON.stringify(a,null,2)})\n});\n\nconst data = await res.json();\nconsole.log(data);`,python:`import requests\nimport json\n\nurl = '${h||`https://usapi.hottask.com${t}`}'\nheaders = ${JSON.stringify(d,null,4)}\ndata = ${JSON.stringify(a,null,2)}\n\nresponse = requests.${s.toLowerCase()}(url, headers=headers, json=data)\ndata = response.json()\nprint(data)`,bash:`curl '${h||`https://usapi.hottask.com${t}`}' \\\n -X ${s} \\\n${Object.entries(d).map((e=>{let[s,t]=e;return` -H '${s}: ${t}' \\`})).join("\n")}\n -d '${JSON.stringify(a)}'`,http:`${s} ${t} HTTP/1.1\nHost: ${l}\n${Object.entries(d).map((e=>{let[s,t]=e;return`${s}: ${t}`})).join("\n")}\n\n${JSON.stringify(a,null,2)}`};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.A,{as:"h3",children:"JavaScript (Fetch API)"}),(0,o.jsx)(r.A,{language:"javascript",children:c.javascript}),(0,o.jsx)(i.A,{as:"h3",children:"Python (Requests Library)"}),(0,o.jsx)(r.A,{language:"python",children:c.python}),(0,o.jsx)(i.A,{as:"h3",children:"cURL"}),(0,o.jsx)(r.A,{language:"bash",children:c.bash}),(0,o.jsx)(i.A,{as:"h3",children:"HTTP Request"}),(0,o.jsx)(r.A,{language:"http",children:c.http})]})},u=e=>{let{responseExample:s,responseComments:t,addCommentsToJson:n=a}=e;const i={...s,Version:"1.0.0",Success:!0,Code:200,Message:""},d={...t,Version:"string - API version",Success:"boolean - Operation success status",Code:"integer - HTTP status code",Message:"string - Error message if any"};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{children:"The API response will be a JSON object with the following structure:"}),(0,o.jsx)(r.A,{language:"json",children:n(i,d)})]})},p=e=>{let{errorHandling:s="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,o.jsx)("div",{style:{whiteSpace:"pre-line"},children:s})};function m(e){let{title:s,path:t,method:r="POST",description:i="",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:x={timeZone:"string, required",type:"integer, required"},responseExample:j={Data:"3254a9d0424c4806b9ea3d0763xxxxxx",Version:"1.0.0",Success:!0,Code:200,Message:""},responseComments:f={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 b=(0,n.r)()(t),q="undefined"==typeof window?"usapi.hottask.com":new URL(b||`https://usapi.hottask.com${t}`).host;JSON.stringify(y,null,2),a(m,x),JSON.stringify(y,null,4),a(m,x),r.toLowerCase(),Object.entries(y).map((e=>{let[s,t]=e;return` -H '${s}: ${t}' \\`})).join("\n"),JSON.stringify(m),Object.entries(y).map((e=>{let[s,t]=e;return`${s}: ${t}`})).join("\n"),a(m,x);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d,{path:t,method:r}),(0,o.jsx)(h,{headers:y,headersDescription:w}),(0,o.jsx)(l,{requestBody:m,requestBodyParams:g,addCommentsToJson:a}),(0,o.jsx)(c,{method:r,path:t,requestBody:m,headers:y}),(0,o.jsx)(u,{responseExample:j,responseComments:f,addCommentsToJson:a}),(0,o.jsx)(p,{errorHandling:T})]})}},8175:(e,s,t)=>{t.d(s,{A:()=>i});t(6540);var n=t(5872),r=t(4848);function i(){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,r.jsx)("code",{children:e})}},9357:(e,s,t)=>{t.d(s,{A:()=>o});t(6540);var n=t(5872),r=t(5363),i=t(4848);function o(e){let{children:s}=e;return(0,i.jsx)(r.A,{children:()=>{const e=(0,n.K)()();if("function"==typeof s){const t=s(e);return(0,i.jsx)("div",{className:"markdown markdown--section",children:t})}return(0,i.jsx)("code",{children:e})}})}},3532:(e,s,t)=>{function n(){return function(e){if("undefined"==typeof window)return"";const s=window.location.hostname;let t="";return t="www.newoaks.ai"==s||"newoaks.ai"==s?"https://usapi.hottask.com":"eu.newoaks.ai"==s?"https://euapi.hottask.com":`https://${s}`,e?`${t}${e.startsWith("/")?e:`/${e}`}`:t}}t.d(s,{r:()=>n})},5872:(e,s,t)=>{function n(){return function(){return"undefined"==typeof window?"":window.location.hostname}}t.d(s,{K:()=>n})}}]);