Skip to content

Commit

Permalink
Integração com n8n
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed May 9, 2023
1 parent f36e6c6 commit 1beb8c6
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"pino-pretty": "^10.0.0",
"qrcode-terminal": "^0.12.0",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"sequelize": "^5.22.3",
"sequelize-cli": "^5.5.1",
"sequelize-typescript": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { QueryInterface } from "sequelize";

module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.bulkInsert(
"Integrations",
[
{
key: "urlApiN8N",
value: "",
createdAt: new Date(),
updatedAt: new Date()
}
],
{}
);
},

down: (queryInterface: QueryInterface) => {
return queryInterface.bulkDelete("Integrations", {});
}
};
24 changes: 24 additions & 0 deletions backend/src/services/WbotServices/wbotMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Contact from "../../models/Contact";
import Ticket from "../../models/Ticket";
import Message from "../../models/Message";
import Settings from "../../models/Setting";
import Integration from "../../models/Integration";

import { getIO } from "../../libs/socket";
import CreateMessageService from "../MessageServices/CreateMessageService";
Expand All @@ -29,6 +30,8 @@ import UpdateTicketService from "../TicketServices/UpdateTicketService";
import CreateContactService from "../ContactServices/CreateContactService";
import formatBody from "../../helpers/Mustache";

const request = require("request");

interface Session extends Client {
id?: number;
}
Expand Down Expand Up @@ -350,6 +353,27 @@ const handleMessage = async (
return;
}

const Integrationdb = await Integration.findOne({
where: { key: "urlApiN8N" }
});

if (Integrationdb?.value) {
const options = {
method: "POST",
url: Integrationdb?.value,
headers: {
"Content-Type": "application/json"
},
json: msg
};
try {
const response = await request(options);
console.log(response.body);
} catch (error) {
throw new Error(error);
}
}

// IGNORAR MENSAGENS DE GRUPO
const Settingdb = await Settings.findOne({
where: { key: "CheckMsgIsGroup" }
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 07/05/2023

- []()

### 05/05/2023

- [Número do cliente trucado para Atendente com verificação individual](https://github.com/rtenorioh/Press-Ticket/commit/f36e6c6f8ae2a3cd29a0defdc14a8a79a726cbcb).

### 04/05/2023

- [Integração com ChatGPT](https://github.com/rtenorioh/Press-Ticket/commit/6b5d22895917a0901a5a8e62f5b40a7acfeeece8); e
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/pages/Integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ const Integrations = () => {
</Paper>
</Paper>

<Paper className={classes.paper1}>
<Typography align="center" variant="body1">
{i18n.t("integrations.integrations.n8n.title")}
</Typography>
<Paper elevation={4} className={classes.paper}>
<TextField
style={{ width: "100%" }}
id="urlApiN8N"
name="urlApiN8N"
margin="dense"
label={i18n.t("integrations.integrations.n8n.urlApiN8N")}
variant="outlined"
value={integrations && integrations.length > 0 && getIntegrationValue("urlApiN8N")}
onChange={handleChangeIntegration}
fullWidth
/>
</Paper>
</Paper>

</Container>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ const messages = {
title: "OpenAI",
organization: "Organization ID",
apikey: "KEY"
},
n8n: {
title: "N8N",
urlApiN8N: "URL API N8N"
}
},
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ const messages = {
title: "OpenAI",
organization: "Organization ID",
apikey: "KEY"
},
n8n: {
title: "N8N",
urlApiN8N: "URL API N8N"
}
},
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ const messages = {
title: "OpenAI",
organization: "Organization ID",
apikey: "KEY"
},
n8n: {
title: "N8N",
urlApiN8N: "URL API N8N"
}
},
},
Expand Down

0 comments on commit 1beb8c6

Please sign in to comment.