Skip to content

Commit

Permalink
Ticket enviado por API sendo encerrado automaticamente e recebimento …
Browse files Browse the repository at this point in the history
…de resposta do envio da API
  • Loading branch information
rtenorioh authored Jun 8, 2022
1 parent 9aec101 commit 30c3044
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 9 deletions.
26 changes: 17 additions & 9 deletions backend/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GetProfilePicUrl from "../services/WbotServices/GetProfilePicUrl";
import SendWhatsAppMedia from "../services/WbotServices/SendWhatsAppMedia";
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
import ListSettingsServiceOne from "../services/SettingServices/ListSettingsServiceOne";

type WhatsappData = {
whatsappId: number;
Expand Down Expand Up @@ -98,21 +99,28 @@ export const index = async (req: Request, res: Response): Promise<Response> => {

const contactAndTicket = await createContact(whatsappId, newContact.number);

let resp: any;

if (medias) {
await Promise.all(
medias.map(async (media: Express.Multer.File) => {
await SendWhatsAppMedia({ body, media, ticket: contactAndTicket });
resp = await SendWhatsAppMedia({ body, media, ticket: contactAndTicket });
})
);
} else {
await SendWhatsAppMessage({ body, ticket: contactAndTicket, quotedMsg });
resp = await SendWhatsAppMessage({ body, ticket: contactAndTicket, quotedMsg });
}

setTimeout(async () => {
await UpdateTicketService({
ticketId: contactAndTicket.id,
ticketData: { status: "closed" }
});
}, 1000);
return res.send({ error: "SUCCESS" });
const listSettingsService = await ListSettingsServiceOne({ key: "closeTicketApi" });
var closeTicketApi = listSettingsService?.value;

if (closeTicketApi === 'enabled') {
setTimeout(async () => {
await UpdateTicketService({
ticketId: contactAndTicket.id,
ticketData: { status: "closed" }
});
}, 1000);
}
return res.send({ error: resp });
};
29 changes: 29 additions & 0 deletions frontend/src/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,35 @@ const Settings = () => {
</Paper>
</Tooltip>

<Typography variant="body2" gutterBottom></Typography>
<Tooltip title={i18n.t("settings.settings.closeTicketApi.note")}>
<Paper className={classes.paper}>

<Typography variant="body1">
{i18n.t("settings.settings.closeTicketApi.name")}
</Typography>
<Select
margin="dense"
variant="outlined"
native
id="closeTicketApi-setting"
name="closeTicketApi"
value={
settings && settings.length > 0 && getSettingValue("closeTicketApi")
}
className={classes.settingOption}
onChange={handleChangeSetting}
>
<option value="enabled">
{i18n.t("settings.settings.closeTicketApi.options.enabled")}
</option>
<option value="disabled">
{i18n.t("settings.settings.closeTicketApi.options.disabled")}
</option>
</Select>
</Paper>
</Tooltip>

<Typography variant="body2" gutterBottom></Typography>
<Tooltip title={i18n.t("settings.settings.timeCreateNewTicket.note")}>
<Paper className={classes.paper} elevation={3}>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ const messages = {
disabled: "Closed",
},
},
closeTicketApi: {
name: "Close Ticket sent API",
note: "Automatically closes ticket when submitted via API",
options: {
enabled: "Enabled",
disabled: "Disabled",
},
},
messagesList: {
header: {
assignedTo: "Assigned to:",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ const messages = {
disabled: "Cerrado",
},
},
closeTicketApi: {
name: "Cerrar ticket enviado API",
note: "Cierra automáticamente el ticket cuando se envía a través de API",
options: {
enabled: "Habilitado",
disabled: "Habilitado",
},
},
timeCreateNewTicket: {
name: "Crear nuevo ticket después",
note: "Selecciona el tiempo que tardará en abrir un nuevo ticket si el cliente te vuelve a contactar",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ const messages = {
disabled: "Fechado",
},
},
closeTicketApi: {
name: "Encerrar Ticket enviado API",
note: "Fecha automaticamente o ticket quando enviado por API",
options: {
enabled: "Ativado",
disabled: "Desativado",
},
},
timeCreateNewTicket: {
name: "Cria novo ticket após",
note: "Selecione o tempo que será necessário para abrir um novo ticket, caso o cliente entre em contatos novamente",
Expand Down

0 comments on commit 30c3044

Please sign in to comment.