n8n-nodes-digitalsac 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # n8n-nodes-digitalsac
2
+
3
+ Este pacote adiciona um nó personalizado ao n8n para interagir com a API do Digitalsac.
4
+
5
+ ## Funcionalidades
6
+
7
+ - Validar número de WhatsApp
8
+ - Validar CPF
9
+ - Validar Data
10
+ - Listar Filas
11
+ - Listar Atendentes
12
+ - Transferir para Fila
13
+ - Transferir para Atendente
14
+ - Fechar Ticket
15
+
16
+ ## Instalação
17
+
18
+ ```bash
19
+ npm install n8n-nodes-digitalsac
20
+ ```
21
+
22
+ ## Autenticação
23
+
24
+ Configure as credenciais Digitalsac com a URL base e seu Bearer Token.
@@ -0,0 +1,25 @@
1
+ import {
2
+ ICredentialType,
3
+ NodePropertyTypes,
4
+ } from 'n8n-workflow';
5
+
6
+ export class DigitalsacApi implements ICredentialType {
7
+ name = 'digitalsacApi';
8
+ displayName = 'Izing Pro Digitalsac API';
9
+ documentationUrl = '';
10
+ properties = [
11
+ {
12
+ displayName: 'API Base URL',
13
+ name: 'baseUrl',
14
+ type: 'string' as NodePropertyTypes,
15
+ default: 'https://example.digitalsac.io',
16
+ description: 'Ex: https://seudominio.digitalsac.com.br',
17
+ },
18
+ {
19
+ displayName: 'Bearer Token',
20
+ name: 'token',
21
+ type: 'string' as NodePropertyTypes,
22
+ default: '',
23
+ },
24
+ ];
25
+ }
@@ -0,0 +1,148 @@
1
+ import {
2
+ IExecuteFunctions,
3
+ INodeExecutionData,
4
+ INodeType,
5
+ INodeTypeDescription,
6
+ } from 'n8n-workflow';
7
+
8
+ export class Digitalsac implements INodeType {
9
+ description: INodeTypeDescription = {
10
+ displayName: 'Digitalsac Izing Pro',
11
+ name: 'digitalsac',
12
+ icon: 'file:digitalsac.svg',
13
+ group: ['transform'],
14
+ version: 1,
15
+ description: 'Interage com a API do Digitalsac',
16
+ defaults: {
17
+ name: 'Digitalsac',
18
+ },
19
+ inputs: ['main'],
20
+ outputs: ['main'],
21
+ credentials: [
22
+ {
23
+ name: 'digitalsacApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ properties: [
28
+ {
29
+ displayName: 'Operação',
30
+ name: 'operation',
31
+ type: 'options',
32
+ options: [
33
+ { name: 'Validar WhatsApp', value: 'validateWhatsapp' },
34
+ { name: 'Validar CPF', value: 'validateCpf' },
35
+ { name: 'Validar Data', value: 'validateDate' },
36
+ { name: 'Listar Filas', value: 'listQueues' },
37
+ { name: 'Listar Atendentes', value: 'listAgents' },
38
+ { name: 'Transferir para Fila', value: 'transferQueue' },
39
+ { name: 'Transferir para Atendente', value: 'transferAgent' },
40
+ { name: 'Fechar Ticket', value: 'closeTicket' },
41
+ { name: 'Enviar Mensagem', value: 'sendMessage' },
42
+ ],
43
+ default: 'validateWhatsapp',
44
+ },
45
+ {
46
+ displayName: 'Parâmetro',
47
+ name: 'param',
48
+ type: 'string',
49
+ default: '',
50
+ displayOptions: {
51
+ show: {
52
+ operation: ['validateWhatsapp', 'validateCpf', 'sendMessage'],
53
+ },
54
+ },
55
+ description: 'Número, CPF ou UUID da mensagem (conforme operação)',
56
+ },
57
+ {
58
+ displayName: 'Dados (JSON)',
59
+ name: 'bodyData',
60
+ type: 'json',
61
+ default: '',
62
+ displayOptions: {
63
+ show: {
64
+ operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket', 'sendMessage'],
65
+ },
66
+ },
67
+ },
68
+ ],
69
+ };
70
+
71
+ async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
72
+ const items = this.getInputData();
73
+ const returnData: INodeExecutionData[] = [];
74
+
75
+ const credentials = await this.getCredentials('digitalsacApi');
76
+ const baseUrl = credentials.baseUrl;
77
+ const token = credentials.token;
78
+
79
+ for (let i = 0; i < items.length; i++) {
80
+ const operation = this.getNodeParameter('operation', i) as string;
81
+ let responseData;
82
+
83
+ const headers = {
84
+ Authorization: `Bearer ${token}`,
85
+ 'Content-Type': 'application/json',
86
+ Accept: 'application/json',
87
+ };
88
+
89
+ let url = '';
90
+ let method: 'GET' | 'POST' = 'GET';
91
+ let body;
92
+ let param = this.getNodeParameter('param', i, '') as string;
93
+
94
+ switch (operation) {
95
+ case 'validateWhatsapp':
96
+ url = `/typebot/whatsappnumber/${param}`;
97
+ break;
98
+ case 'validateCpf':
99
+ url = `/typebot/validate/cpf/${param}`;
100
+ break;
101
+ case 'validateDate':
102
+ url = '/typebot/validate/data';
103
+ method = 'POST';
104
+ body = this.getNodeParameter('bodyData', i);
105
+ break;
106
+ case 'listQueues':
107
+ url = '/typebot/listar_filas';
108
+ break;
109
+ case 'listAgents':
110
+ url = '/typebot/listar_atendentes';
111
+ break;
112
+ case 'transferQueue':
113
+ url = '/typebot/transferir_para_fila';
114
+ method = 'POST';
115
+ body = this.getNodeParameter('bodyData', i);
116
+ break;
117
+ case 'transferAgent':
118
+ url = '/typebot/transferir_para_atendente';
119
+ method = 'POST';
120
+ body = this.getNodeParameter('bodyData', i);
121
+ break;
122
+ case 'closeTicket':
123
+ url = '/typebot/fechar_ticket';
124
+ method = 'POST';
125
+ body = this.getNodeParameter('bodyData', i);
126
+ break;
127
+ case 'sendMessage':
128
+ url = `/v1/api/external/${param}`;
129
+ method = 'POST';
130
+ body = this.getNodeParameter('bodyData', i);
131
+ break;
132
+ }
133
+
134
+ const options = {
135
+ method,
136
+ headers,
137
+ body: body ? JSON.stringify(body) : undefined,
138
+ uri: `${baseUrl}${url}`,
139
+ json: true,
140
+ };
141
+
142
+ responseData = await this.helpers.request(options);
143
+ returnData.push({ json: responseData });
144
+ }
145
+
146
+ return [returnData];
147
+ }
148
+ }