n8n-nodes-underchat 0.1.2 → 0.1.4
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 +11 -5
- package/dist/credentials/UnderChatApi.credentials.d.ts +1 -1
- package/dist/credentials/UnderChatApi.credentials.js +2 -12
- package/dist/credentials/UnderChatApi.credentials.js.map +1 -1
- package/dist/nodes/UnderChat/GenericFunctions.d.ts +3 -2
- package/dist/nodes/UnderChat/GenericFunctions.js +24 -1
- package/dist/nodes/UnderChat/GenericFunctions.js.map +1 -1
- package/dist/nodes/UnderChat/UnderChat.node.d.ts +14 -1
- package/dist/nodes/UnderChat/UnderChat.node.js +341 -32
- package/dist/nodes/UnderChat/UnderChat.node.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- /package/dist/nodes/UnderChat/{underchat.dark.svg → underchat-logo.dark.svg} +0 -0
- /package/dist/nodes/UnderChat/{underchat.svg → underchat-logo.svg} +0 -0
package/README.md
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Community Node do n8n para integrar workflows à API pública da UnderChat.
|
|
4
4
|
|
|
5
|
-
## Operações
|
|
5
|
+
## Operações
|
|
6
6
|
|
|
7
7
|
- Buscar contato por telefone
|
|
8
8
|
- Criar contato
|
|
9
9
|
- Enviar mensagem de texto por `chat_id`
|
|
10
10
|
- Enviar mensagem por telefone, criando o contato quando necessário
|
|
11
11
|
- Enviar template oficial em uma conversa
|
|
12
|
+
- Listar executores, usuários e setores
|
|
13
|
+
- Transferir um chat para outro usuário, setor ou worker
|
|
14
|
+
|
|
15
|
+
Os campos de executor, usuário, setor e worker oferecem busca na API e também
|
|
16
|
+
permitem informar o UUID manualmente.
|
|
12
17
|
|
|
13
18
|
A operação **Enviar mensagem por telefone** executa automaticamente:
|
|
14
19
|
|
|
@@ -22,7 +27,7 @@ buscar contato → criar se necessário → iniciar conversa → enviar mensagem
|
|
|
22
27
|
- n8n com suporte a Community Nodes
|
|
23
28
|
- Conta UnderChat com plano ativo
|
|
24
29
|
- Token da API pública
|
|
25
|
-
-
|
|
30
|
+
- Um usuário executor ativo nas operações que exigem contexto de usuário
|
|
26
31
|
|
|
27
32
|
## Desenvolvimento
|
|
28
33
|
|
|
@@ -40,11 +45,12 @@ O modo de desenvolvimento inicia uma instância do n8n com o node carregado.
|
|
|
40
45
|
No n8n, crie uma credencial **UnderChat API** e informe:
|
|
41
46
|
|
|
42
47
|
- **API Key:** token gerado em `Integração → API pública`.
|
|
43
|
-
- **ID do Usuário Executor:** UUID do usuário cujas permissões serão aplicadas.
|
|
44
48
|
- **URL Base:** mantenha `https://api-public.underchat.com.br/v1` em produção.
|
|
45
49
|
|
|
46
|
-
A
|
|
47
|
-
|
|
50
|
+
A API key identifica a conta e é enviada no header `keyapi`. Não existe um
|
|
51
|
+
executor padrão: em cada node, selecione explicitamente o usuário executor que
|
|
52
|
+
deve realizar a operação. O node consulta os executores ativos da conta e envia
|
|
53
|
+
o selecionado no header `x-underchat-user-id`.
|
|
48
54
|
|
|
49
55
|
## Teste seguro
|
|
50
56
|
|
|
@@ -2,7 +2,7 @@ import type { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INo
|
|
|
2
2
|
export declare class UnderChatApi implements ICredentialType {
|
|
3
3
|
name: string;
|
|
4
4
|
displayName: string;
|
|
5
|
-
icon: "file:../nodes/UnderChat/underchat.svg";
|
|
5
|
+
icon: "file:../nodes/UnderChat/underchat-logo.svg";
|
|
6
6
|
documentationUrl: string;
|
|
7
7
|
properties: INodeProperties[];
|
|
8
8
|
authenticate: IAuthenticateGeneric;
|
|
@@ -5,7 +5,7 @@ class UnderChatApi {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
this.name = 'underChatApi';
|
|
7
7
|
this.displayName = 'UnderChat API';
|
|
8
|
-
this.icon = 'file:../nodes/UnderChat/underchat.svg';
|
|
8
|
+
this.icon = 'file:../nodes/UnderChat/underchat-logo.svg';
|
|
9
9
|
this.documentationUrl = 'https://docs.underchat.com.br/guias/primeiros-passos';
|
|
10
10
|
this.properties = [
|
|
11
11
|
{
|
|
@@ -17,14 +17,6 @@ class UnderChatApi {
|
|
|
17
17
|
required: true,
|
|
18
18
|
description: 'Token gerado em Integração → API pública no painel da UnderChat',
|
|
19
19
|
},
|
|
20
|
-
{
|
|
21
|
-
displayName: 'ID do Usuário Executor',
|
|
22
|
-
name: 'userId',
|
|
23
|
-
type: 'string',
|
|
24
|
-
default: '',
|
|
25
|
-
required: true,
|
|
26
|
-
description: 'UUID do usuário que executará as operações e cujas permissões serão aplicadas',
|
|
27
|
-
},
|
|
28
20
|
{
|
|
29
21
|
displayName: 'URL Base',
|
|
30
22
|
name: 'baseUrl',
|
|
@@ -39,15 +31,13 @@ class UnderChatApi {
|
|
|
39
31
|
properties: {
|
|
40
32
|
headers: {
|
|
41
33
|
keyapi: '={{$credentials.apiKey}}',
|
|
42
|
-
'x-underchat-user-id': '={{$credentials.userId}}',
|
|
43
34
|
},
|
|
44
35
|
},
|
|
45
36
|
};
|
|
46
37
|
this.test = {
|
|
47
38
|
request: {
|
|
48
39
|
baseURL: '={{$credentials.baseUrl.replace(/\\/$/, "")}}',
|
|
49
|
-
url: '/
|
|
50
|
-
qs: { status: 'my_chats', per_page: 1 },
|
|
40
|
+
url: '/user/all',
|
|
51
41
|
},
|
|
52
42
|
};
|
|
53
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnderChatApi.credentials.js","sourceRoot":"","sources":["../../credentials/UnderChatApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,YAAY;IAAzB;QACC,SAAI,GAAG,cAAc,CAAC;QAEtB,gBAAW,GAAG,eAAe,CAAC;QAE9B,SAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"UnderChatApi.credentials.js","sourceRoot":"","sources":["../../credentials/UnderChatApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,YAAY;IAAzB;QACC,SAAI,GAAG,cAAc,CAAC;QAEtB,gBAAW,GAAG,eAAe,CAAC;QAE9B,SAAI,GAAG,4CAAqD,CAAC;QAE7D,qBAAgB,GAAG,sDAAsD,CAAC;QAE1E,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,iEAAiE;aAC9E;YACD;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,wCAAwC;gBACjD,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,sDAAsD;aACnE;SACD,CAAC;QAEF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACX,OAAO,EAAE;oBACR,MAAM,EAAE,0BAA0B;iBAClC;aACD;SACD,CAAC;QAEF,SAAI,GAA2B;YAC9B,OAAO,EAAE;gBACR,OAAO,EAAE,+CAA+C;gBACxD,GAAG,EAAE,WAAW;aAChB;SACD,CAAC;IACH,CAAC;CAAA;AA5CD,oCA4CC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { IDataObject, IExecuteFunctions, IHttpRequestMethods } from 'n8n-workflow';
|
|
2
|
-
export declare function underChatApiRequest(this: IExecuteFunctions, method: IHttpRequestMethods, endpoint: string, body?: IDataObject, qs?: IDataObject): Promise<IDataObject>;
|
|
1
|
+
import type { IDataObject, IExecuteFunctions, IHttpRequestMethods, ILoadOptionsFunctions } from 'n8n-workflow';
|
|
2
|
+
export declare function underChatApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, endpoint: string, body?: IDataObject, qs?: IDataObject, executorId?: string): Promise<IDataObject>;
|
|
3
3
|
export declare function responseData(response: IDataObject): unknown;
|
|
4
|
+
export declare function collectionRecords(value: unknown): IDataObject[];
|
|
4
5
|
export declare function firstRecord(response: IDataObject): IDataObject | undefined;
|
|
5
6
|
export declare function getOpaqueId(record: IDataObject | undefined, names: string[]): string | undefined;
|
|
6
7
|
export declare function parseJsonObject(value: string): IDataObject;
|
|
@@ -2,20 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.underChatApiRequest = underChatApiRequest;
|
|
4
4
|
exports.responseData = responseData;
|
|
5
|
+
exports.collectionRecords = collectionRecords;
|
|
5
6
|
exports.firstRecord = firstRecord;
|
|
6
7
|
exports.getOpaqueId = getOpaqueId;
|
|
7
8
|
exports.parseJsonObject = parseJsonObject;
|
|
8
9
|
exports.isNotFoundError = isNotFoundError;
|
|
9
10
|
exports.parseJsonArray = parseJsonArray;
|
|
10
11
|
exports.withoutEmptyValues = withoutEmptyValues;
|
|
11
|
-
async function underChatApiRequest(method, endpoint, body = {}, qs = {}) {
|
|
12
|
+
async function underChatApiRequest(method, endpoint, body = {}, qs = {}, executorId) {
|
|
12
13
|
const credentials = await this.getCredentials('underChatApi');
|
|
13
14
|
const baseUrl = String(credentials.baseUrl).replace(/\/$/, '');
|
|
15
|
+
const legacyExecutorId = typeof credentials.userId === 'string' ? credentials.userId : '';
|
|
16
|
+
const resolvedExecutorId = executorId || legacyExecutorId;
|
|
14
17
|
const options = {
|
|
15
18
|
method,
|
|
16
19
|
url: `${baseUrl}${endpoint}`,
|
|
17
20
|
json: true,
|
|
18
21
|
};
|
|
22
|
+
if (endpoint !== '/user/all' && resolvedExecutorId) {
|
|
23
|
+
options.headers = { 'x-underchat-user-id': resolvedExecutorId };
|
|
24
|
+
}
|
|
19
25
|
if (Object.keys(body).length > 0)
|
|
20
26
|
options.body = body;
|
|
21
27
|
if (Object.keys(qs).length > 0)
|
|
@@ -26,6 +32,23 @@ function responseData(response) {
|
|
|
26
32
|
var _a;
|
|
27
33
|
return (_a = response.data) !== null && _a !== void 0 ? _a : response;
|
|
28
34
|
}
|
|
35
|
+
function collectionRecords(value) {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return value.filter((item) => Boolean(item) && typeof item === 'object' && !Array.isArray(item));
|
|
38
|
+
}
|
|
39
|
+
if (!value || typeof value !== 'object')
|
|
40
|
+
return [];
|
|
41
|
+
const record = value;
|
|
42
|
+
for (const key of ['data', 'results', 'items', 'users', 'sectors', 'workers']) {
|
|
43
|
+
const nested = record[key];
|
|
44
|
+
if (nested !== undefined && nested !== value) {
|
|
45
|
+
const records = collectionRecords(nested);
|
|
46
|
+
if (records.length > 0)
|
|
47
|
+
return records;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
29
52
|
function firstRecord(response) {
|
|
30
53
|
const data = responseData(response);
|
|
31
54
|
if (Array.isArray(data))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/UnderChat/GenericFunctions.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/UnderChat/GenericFunctions.ts"],"names":[],"mappings":";;AAQA,kDA6BC;AAED,oCAEC;AAED,8CAiBC;AAED,kCASC;AAED,kCAOC;AAED,0CAKC;AAED,0CAiBC;AAED,wCAKC;AAED,gDAIC;AA/GM,KAAK,UAAU,mBAAmB,CAExC,MAA2B,EAC3B,QAAgB,EAChB,OAAoB,EAAE,EACtB,KAAkB,EAAE,EACpB,UAAmB;IAEnB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,gBAAgB,GAAG,OAAO,WAAW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CAAC;AAChC,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAmB;IACrD,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,SAAS,CAAC,CACjF,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
1
|
+
import type { IExecuteFunctions, ILoadOptionsFunctions, INodeExecutionData, INodeListSearchResult, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
declare function searchExecutors(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
|
|
3
|
+
declare function searchWorkers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
|
|
4
|
+
declare function searchSectors(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
|
|
5
|
+
declare function searchUsers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
|
|
2
6
|
export declare class UnderChat implements INodeType {
|
|
3
7
|
description: INodeTypeDescription;
|
|
8
|
+
methods: {
|
|
9
|
+
listSearch: {
|
|
10
|
+
searchExecutors: typeof searchExecutors;
|
|
11
|
+
searchSectors: typeof searchSectors;
|
|
12
|
+
searchUsers: typeof searchUsers;
|
|
13
|
+
searchWorkers: typeof searchWorkers;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
4
16
|
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
17
|
}
|
|
18
|
+
export {};
|