1import{aj as c,r as n,p as e,ag as P,S as d,y as R,bj as O,x as N,L as y,T as _,w as T,bh as M,B as A,bF as L,N as k,z as q}from"./index-C9IH3k-2.js";import{D as H,u as W}from"./HelperMethods-C-ewwU_x.js";import{P as $}from"./PageDescription-BrOUsEZE.js";import{K}from"./KeywordTagsInput-BkCTfm_l.js";import{N as z,T as G,J as V}from"./TemplateUtil-D1DzmWLm.js";import{S as F}from"./index-8jSYgZzf.js";import{O as D}from"./OutSendMessagePreview-VUmnjP6y.js";import{F as Y}from"./Table-isZ0WXp4.js";import{P as J}from"./index-C0dhduHx.js";import"./Wrapper-ChjuDa3w.js";import"./tiny-invariant-CopsF_GD.js";import"./MenuOutlined-DhPBrr1e.js";import"./useTemplateDetails-DA6kn5sZ.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";const U=({jsonData:i,hideBSVRMessage:g,isOpen:p})=>{const[r]=c.useForm(),[j,x]=n.useState([]),[l,h]=n.useState(!0),[m,u]=n.useState(!1),[o,b]=n.useState(!1),[f,C]=n.useState(""),S=async()=>{b(!0);try{const s=await R("/api/v1/message/preComposed/list/idName",{name:f});s&&x(s.data)}catch{}finally{b(!1)}};n.useEffect(()=>{S()},[f]),n.useEffect(()=>{p&&(r.resetFields(),Object.keys(i).length>0?(r.setFieldsValue({...i,conditionText:Array.isArray(i.conditionText)?i.conditionText:i.conditionText?[i.conditionText]:[]}),h(i.active)):(r.setFieldsValue({active:!0,priority:0}),h(!0)))},[i]);const w=async t=>{const s={...t};Object.keys(i).length>0&&(s.id=i.id),u(!0);try{const a=await R("/api/v1/basicChatbot/save",s);if(a.status===200)O.success({title:"Success",description:a.data.message||"Chatbot rule saved successfully!"}),g();else throw new Error(a?.data?.message||"Failed to save")}catch(a){O.error({title:"Error",description:a.message||"Something went wrong. Please try again later."})}finally{u(!1)}},v=H(t=>{C(t)},300),E=t=>{h(t),r.setFieldsValue({active:t})};return e.jsx(z,{title:Object.keys(i).length>0?"Edit Chat Bot Rule":"Create Chat Bot Rule",open:p,onOk:()=>r.submit(),onCancel:()=>g(),style:{minWidth:700},okButtonProps:{loading:m},cancelButtonProps:{disabled:m},children:e.jsxs(c,{form:r,name:"basicChatbotForm",labelCol:{span:5},wrapperCol:{span:16},onFinish:w,layout:"horizontal",preserve:!1,children:[e.jsx(c.Item,{label:"Name",name:"name",rules:[{required:!0,message:"Name is required"}],children:e.jsx(P,{placeholder:"Enter rule name",maxLength:100})}),e.jsx(c.Item,{label:"Type",name:"type",rules:[{required:!0,message:"Rule type is required"}],children:e.jsxs(d,{placeholder:"Select match type",showSearch:!0,optionFilterProp:"children",children:[e.jsx(d.Option,{value:"CONTAINS",children:"Contains"}),e.jsx(d.Option,{value:"BEGINS_WITH",children:"Begin With"}),e.jsx(d.Option,{value:"ENDS_WITH",children:"End With"}),e.jsx(d.Option,{value:"EXACT_MATCH",children:"Exact Match"}),e.jsx(d.Option,{value:"PATTERN_MATCH",children:"Pattern Match"})]})}),e.jsx(c.Item,{label:"Match text",name:"conditionText",rules:[{required:!0,type:"array",message:"At least one matching text is required"}],tooltip:"The rule fires when an incoming message matches the selected type against ANY of these keywords.",children:e.jsx(K,{placeholder:"Type keyword",color:"blue"})}),e.jsx(c.Item,{label:"Response message",name:"preComposedMessageId",rules:[{required:!0,message:"Response message is required"}],children:e.jsx(d,{placeholder:"Select response message",showSearch:!0,optionFilterProp:"children",onSearch:v,filterOption:!1,loading:o,children:j?.map(t=>e.jsx(d.Option,{value:t.id,children:t.name},t.id))})}),e.jsx(c.Item,{name:"active",label:"Status",valuePropName:"checked",children:e.jsx(F,{checked:l,onChange:E})}),e.jsx(c.Item,{label:"Priority",name:"priority",children:e.jsx(P,{type:"number",min:0})})]})})},me=()=>{const[i,g]=n.useState([]),[p,r]=n.useState(!1),[j,x]=n.useState({}),[l,h]=n.useState(null),[m,u]=n.useState({}),o=W();n.useEffect(()=>{p||b()},[p]);const b=async()=>{try{const t=await N("/api/v1/basicChatbot/list");t&&g(t.data)}catch{}},f=async t=>{if(!(!t||m[t]))try{const s=await N(`/api/v1/message/preComposed/${t}`);s&&s.data?u(a=>({...a,[t]:s.data})):u(a=>({...a,[t]:null}))}catch{u(s=>({...s,[t]:null}))}},C=()=>{x({}),r(!0)},S=t=>{x(t),r(!0)},w=async t=>{h(t);const s=`delete-${t}`;try{k.loading({content:"Deleting chatbot rule...",key:s});const a=await q(`/api/v1/basicChatbot/${t}`);a?(g(I=>
1I.filter(B=>B.id!==t)),k.success({content:"Basic chatbot deleted successfully!",key:s})):k.error({content:a?.data?.message||"Failed to delete basic chatbot. Please try again.",key:s})}catch{}finally{h(null)}},v=()=>{r(!1),x({})},E=[{title:"Name",dataIndex:"name",key:"name"},{title:"Type",dataIndex:"type",key:"type"},{title:"Match text",dataIndex:"conditionText",key:"conditionText",render:t=>{const s=Array.isArray(t)?t:t?[t]:[];return e.jsx(y,{wrap:!0,gap:"4px",children:s.map(a=>e.jsx(G,{color:"blue",style:{marginInlineEnd:0},children:a},a))})}},{title:"Response message",dataIndex:"preComposedMessageId",key:"responseMessage"},{title:"Active",dataIndex:"active",key:"active",render:t=>e.jsx(F,{checked:t,disabled:!0})},{title:"Action",dataIndex:"action",key:"action",render:(t,s)=>e.jsxs(y,{gap:"small",children:[e.jsx(T,{title:o("manage_chatbots")?"Edit":M,children:e.jsx(A,{icon:e.jsx(L,{}),onClick:()=>S(s),disabled:!o("manage_chatbots")})}),e.jsx(J,{title:"Delete basic chatbot",description:"Are you sure you want to delete this basic chatbot?",onConfirm:()=>w(s.id),okText:"Yes",cancelText:"No",okButtonProps:{loading:l===s.id},disabled:l!==null||!o("manage_chatbots"),children:e.jsx(T,{title:o("manage_chatbots")?l!==null?"Operation in progress":"Delete":M,children:e.jsx(A,{danger:!0,icon:e.jsx(V,{}),loading:l===s.id,disabled:l!==null&&l!==s.id||!o("manage_chatbots")})})})]})}];return e.jsxs(e.Fragment,{children:[e.jsxs(y,{vertical:!0,gap:"large",children:[e.jsxs(y,{justify:"space-between",wrap:!0,children:[e.jsx(_.Title,{level:4,style:{margin:0},children:"Basic Chat Bot"}),e.jsx(T,{title:o("manage_chatbots")?"":M,children:e.jsx(A,{type:"primary",onClick:C,disabled:!o("manage_chatbots"),children:"Create Chat Bot"})})]}),e.jsx($,{description:"What is Basic Chat Bot ?",children:e.jsxs("ul",{style:{margin:0,paddingLeft:18},children:[e.jsx("li",{children:"Allows you to create automated responses to specific user messages using selected Canned messages."}),e.jsx("li",{children:"Each rule consists of message matching criteria and a predefined response."}),e.jsx("li",{children:"When a user's message matches your rule (exact match, contains text, or regex), the system sends the associated response automatically."}),e.jsx("li",{children:"Helps provide instant replies to common questions, keywords, or phrases without manual intervention."})]})}),e.jsx(Y,{columns:E,dataSource:i,rowKey:"id",pagination:{pageSize:10},scroll:{x:"max-content"},expandable:{expandedRowRender:t=>{const s=t.preComposedMessageId;s&&m[s]===void 0&&f(s);const a=m[s];return e.jsx(y,{wrap:!0,gap:"large",children:a&&a.message&&a.message.length>0?a.message.map((I,B)=>e.jsx("span",{children:e.jsx(D,{data:{message:I},mediaUse:"PRE_COMPOSED_MESSAGE"})},B)):a===null?e.jsx("span",{children:"No preview available"}):e.jsx("span",{children:"Loading preview..."})})},rowExpandable:t=>t.name!=="Not Expandable"}})]}),p&&e.jsx(U,{isOpen:p,jsonData:j,hideBSVRMessage:v})]})};export{me as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.