Skip to content

Commit

Permalink
option to finish chatbot on wrong answer
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jul 6, 2024
1 parent f23b5db commit bc9619c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/src/services/WbotServices/wbotMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import { cacheLayer } from "../../libs/cache";
import { debounce } from "../../helpers/Debounce";
import { getMessageOptions } from "./SendWhatsAppMedia";
import { makeRandomId } from "../../helpers/MakeRandomId";
import { GetCompanySetting } from "../../helpers/CheckSettings";
import Whatsapp from "../../models/Whatsapp";


type Session = WASocket & {
Expand Down Expand Up @@ -1166,6 +1168,15 @@ const handleChartbot = async (ticket: Ticket, msg: WAMessage, wbot: Session, don
const option = queue?.options.find((o) => o.option === messageBody);
if (option) {
await ticket.update({ queueOptionId: option?.id });
} else if (await GetCompanySetting(ticket.companyId, "chatbotAutoExit") === "enabled" ) {
// message didn't identified an option and company setting to exit chatbot
await ticket.update({ chatbot: false });
const whatsapp = await Whatsapp.findByPk(ticket.whatsappId);
const contact = await Contact.findByPk(ticket.contactId);
if (whatsapp.transferMessage) {
const body = formatBody(`\u200e${whatsapp.transferMessage}`, contact);
await SendWhatsAppMessage({ body, ticket });
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions frontend/src/components/Settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function Options(props) {
const [chatbotType, setChatbotType] = useState("");
const [quickMessages, setQuickMessages] = useState("");
const [allowSignup, setAllowSignup] = useState("disabled");
const [chatbotAutoExit, setChatbotAutoExit] = useState("disabled");
const [CheckMsgIsGroup, setCheckMsgIsGroupType] = useState("enabled");

const [loadingUserRating, setLoadingUserRating] = useState(false);
Expand All @@ -96,6 +97,7 @@ export default function Options(props) {
const [loadingChatbotType, setLoadingChatbotType] = useState(false);
const [loadingQuickMessages, setLoadingQuickMessages] = useState(false);
const [loadingAllowSignup, setLoadingAllowSignup] = useState(false);
const [loadingChatbotAutoExit, setLoadingChatbotAutoExit] = useState(false);
const [loadingCheckMsgIsGroup, setCheckMsgIsGroup] = useState(false);
const { getCurrentUserInfo } = useAuth();
const [currentUser, setCurrentUser] = useState({});
Expand Down Expand Up @@ -130,6 +132,10 @@ export default function Options(props) {
if (chatbotType) {
setChatbotType(chatbotType.value);
}
const chatbotAutoExit = settings.find((s) => s.key === "chatbotAutoExit");
if (chatbotAutoExit) {
setChatbotAutoExit(chatbotAutoExit.value);
}
const allowSignup = settings.find((s) => s.key === "allowSignup");
if (allowSignup) {
setAllowSignup(allowSignup.value);
Expand Down Expand Up @@ -196,6 +202,17 @@ export default function Options(props) {
setLoadingChatbotType(false);
}

async function handleChatbotAutoExit(value) {
setChatbotAutoExit(value);
setLoadingChatbotAutoExit(true);
await update({
key: "chatbotAutoExit",
value,
});
toast.success("Operação atualizada com sucesso.");
setLoadingChatbotAutoExit(false);
}

async function handleQuickMessages(value) {
setQuickMessages(value);
setLoadingQuickMessages(true);
Expand Down Expand Up @@ -336,6 +353,26 @@ export default function Options(props) {
</FormHelperText>
</FormControl>
</Grid>
<Grid xs={12} sm={6} md={4} item>
<FormControl className={classes.selectContainer}>
<InputLabel id="group-type-label">
Saída automática de chatbot
</InputLabel>
<Select
labelId="chatbot-autoexit"
value={chatbotAutoExit}
onChange={async (e) => {
handleChatbotAutoExit(e.target.value);
}}
>
<MenuItem value={"disabled"}>Desativado</MenuItem>
<MenuItem value={"enabled"}>Ativado</MenuItem>
</Select>
<FormHelperText>
{loadingChatbotAutoExit && "Atualizando..."}
</FormHelperText>
</FormControl>
</Grid>
<Grid xs={12} sm={6} md={4} item>
<FormControl className={classes.selectContainer}>
<InputLabel id="quickmessages-label">
Expand Down

0 comments on commit bc9619c

Please sign in to comment.