n8n-nodes-callhuman 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CallHuman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ # n8n-nodes-callhuman
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Call a person from an n8n workflow, read them a message, and **continue down a different branch for each answer**. They answer by pressing a key or in their own words (“yes, we’ll be there, don’t cancel it” → Confirm).
4
+
5
+ ![A workflow with the CallHuman node: one output per option, plus No answer](https://www.callhuman.es/docs/n8n/workflow.webp)
6
+
7
+ No webhooks, Wait or Switch nodes to set up: the node places the call, pauses the execution while the phone rings, and resumes it down the branch of the option the person chose.
8
+
9
+ [CallHuman](https://www.callhuman.es) is an API for **transactional calls**: booking confirmations, approvals, verification codes and on-call alerts. Every call comes from a real phone number (your own on higher plans, or CallHuman’s shared number on the entry plan).
10
+
11
+ ## Install
12
+
13
+ In n8n: **Settings → Community nodes → Install**, and enter:
14
+
15
+ ```text
16
+ n8n-nodes-callhuman
17
+ ```
18
+
19
+ ## Credentials
20
+
21
+ Create an API key in your [CallHuman dashboard](https://www.callhuman.es/app) under **Developers → API keys**, then in n8n: **Credentials → New → CallHuman API** and paste it. n8n checks the key when you save.
22
+
23
+ You need an active CallHuman plan and a phone number to place calls.
24
+
25
+ ## The node: Call and wait for answer
26
+
27
+ <img src="https://www.callhuman.es/docs/n8n/node.webp" alt="CallHuman node settings" width="380" align="right" />
28
+
29
+ | Field | What to enter |
30
+ |---|---|
31
+ | **Phone Number** | International format, e.g. `+34600111222`. Usually mapped from a previous node. |
32
+ | **Message** | What we read when they answer. |
33
+ | **Language** | 19 spoken languages & regional accents across Europe and the Americas (English US/UK, Spanish Spain/LatAm, French France/Canada, Portuguese Portugal/Brazil, German, Italian, Dutch, Polish, Swedish, Danish, Norwegian, Finnish, Catalan, Czech, Turkish). |
34
+ | **Options** | One per answer: a **Label** (“Press 1 or say Confirm”), an optional **ID** (returned as `option_id`) and an optional **Reply** said back before hanging up. An option can have **Sub-options** to open a submenu (one level; 0 or “back” returns). Your plan sets how many answers a call can offer. |
35
+ | **Additional Fields** | **Retries** (0–5) and **Retry Delay** (60–3600 s) if nobody answers, it’s busy or voicemail; **Metadata** returned with the result. |
36
+
37
+ **Outputs:** one per answer, named by its label (answers inside a submenu too), plus **No answer** (not answered, voicemail, failed, or answered without choosing). Without options it’s a one-way message (e.g. a code) with **Done** and **No answer**.
38
+
39
+ Each branch receives the result:
40
+
41
+ ```json
42
+ { "id": "call_x9f2k", "status": "answered", "option_id": "change_time", "option_label": "Change time", "answer_method": "voice", "answer_transcript": "I need to change the time", "metadata": { "booking_id": "bk_1042" } }
43
+ ```
44
+
45
+ ### Cancel a call
46
+
47
+ Select the **Cancel Call** operation and pass a `call_…` ID to immediately stop a queued call (including one waiting between retries) or hang up an active call without retrying (`POST /v1/calls/{id}/cancel`). Canceled unanswered calls do not count towards your quota.
48
+
49
+ <br clear="right" />
50
+
51
+ ## Templates
52
+
53
+ Import from **Workflows → Import from file / URL**:
54
+
55
+ | Template | What it does |
56
+ |---|---|
57
+ | [Reconfirm a booking](https://www.callhuman.es/n8n/templates/reconfirm-booking.json) | Confirm, cancel, or a submenu to change time or guests |
58
+ | [Read a verification code](https://www.callhuman.es/n8n/templates/voice-otp.json) | One-way message, no retries; falls back to SMS |
59
+ | [Approve by phone](https://www.callhuman.es/n8n/templates/approval.json) | Approve or reject a payment by voice or keypress |
60
+ | [On-call alert with escalation](https://www.callhuman.es/n8n/templates/on-call-alert.json) | Fast retries, then the backup person |
61
+
62
+ ## Requirements
63
+
64
+ - n8n 1.x or 2.x. CallHuman must reach your n8n over **public https** to send the answer back: n8n Cloud works as is; for self-hosted n8n set `WEBHOOK_URL` to a public https address.
65
+ - If the result never arrives (n8n unreachable), the execution continues through **No answer** after the call’s last possible attempt plus 3 hours.
66
+
67
+ ## Links
68
+
69
+ - [n8n guide](https://www.callhuman.es/docs/n8n) · [Languages](https://www.callhuman.es/docs/languages) · [API reference](https://www.callhuman.es/docs/api-reference) · [Allowed calls](https://www.callhuman.es/docs/allowed-use)
70
+ - Support: hello@callhuman.es
71
+
72
+ ## License
73
+
74
+ MIT
@@ -0,0 +1,13 @@
1
+ import type { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from "n8n-workflow";
2
+ export declare class CallHumanApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ icon: {
6
+ readonly light: "file:callhuman.svg";
7
+ readonly dark: "file:callhuman.dark.svg";
8
+ };
9
+ documentationUrl: string;
10
+ properties: INodeProperties[];
11
+ authenticate: IAuthenticateGeneric;
12
+ test: ICredentialTestRequest;
13
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallHumanApi = void 0;
4
+ class CallHumanApi {
5
+ name = "callHumanApi";
6
+ displayName = "CallHuman API";
7
+ icon = { light: "file:callhuman.svg", dark: "file:callhuman.dark.svg" };
8
+ documentationUrl = "https://www.callhuman.es/docs/n8n";
9
+ properties = [
10
+ {
11
+ displayName: "API Key",
12
+ name: "apiKey",
13
+ type: "string",
14
+ typeOptions: { password: true },
15
+ default: "",
16
+ required: true,
17
+ placeholder: "ch_live_…",
18
+ description: "Create one in your CallHuman dashboard under API keys",
19
+ },
20
+ {
21
+ // Not shown: only to point the node at a test server.
22
+ displayName: "API URL",
23
+ name: "baseUrl",
24
+ type: "hidden",
25
+ default: "https://api.callhuman.es",
26
+ },
27
+ ];
28
+ authenticate = {
29
+ type: "generic",
30
+ properties: { headers: { Authorization: "=Bearer {{$credentials.apiKey}}" } },
31
+ };
32
+ // Checks the key without placing a call.
33
+ test = {
34
+ request: { baseURL: "={{$credentials.baseUrl}}", url: "/v1/project" },
35
+ };
36
+ }
37
+ exports.CallHumanApi = CallHumanApi;
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" fill="none">
2
+ <rect x="9" y="3" width="22" height="34" rx="8" fill="#c6b5fb" stroke="#e9e4f5" stroke-width="2.2"/>
3
+ <rect x="12.5" y="8" width="15" height="21" rx="4.5" fill="#ede7fe" stroke="#e9e4f5" stroke-width="2"/>
4
+ <circle cx="17" cy="16" r="1.4" fill="#e9e4f5"/>
5
+ <circle cx="23" cy="16" r="1.4" fill="#e9e4f5"/>
6
+ <ellipse cx="14.8" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
7
+ <ellipse cx="25.2" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
8
+ <path d="M17.6 20.2q2.4 2.2 4.8 0" stroke="#e9e4f5" stroke-width="1.8" stroke-linecap="round"/>
9
+ <circle cx="20" cy="33" r="1.4" fill="#fff" stroke="#e9e4f5" stroke-width="1.4"/>
10
+ </svg>
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" fill="none">
2
+ <rect x="9" y="3" width="22" height="34" rx="8" fill="#c6b5fb" stroke="#3b3550" stroke-width="2.2"/>
3
+ <rect x="12.5" y="8" width="15" height="21" rx="4.5" fill="#ede7fe" stroke="#3b3550" stroke-width="2"/>
4
+ <circle cx="17" cy="16" r="1.4" fill="#3b3550"/>
5
+ <circle cx="23" cy="16" r="1.4" fill="#3b3550"/>
6
+ <ellipse cx="14.8" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
7
+ <ellipse cx="25.2" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
8
+ <path d="M17.6 20.2q2.4 2.2 4.8 0" stroke="#3b3550" stroke-width="1.8" stroke-linecap="round"/>
9
+ <circle cx="20" cy="33" r="1.4" fill="#fff" stroke="#3b3550" stroke-width="1.4"/>
10
+ </svg>
@@ -0,0 +1,13 @@
1
+ import { type IExecuteFunctions, type INodeExecutionData, type INodeType, type INodeTypeDescription, type IWebhookFunctions, type IWebhookResponseData } from "n8n-workflow";
2
+ export declare class CallHuman implements INodeType {
3
+ description: INodeTypeDescription;
4
+ webhookMethods: {
5
+ default: {
6
+ checkExists(): Promise<boolean>;
7
+ create(): Promise<boolean>;
8
+ delete(): Promise<boolean>;
9
+ };
10
+ };
11
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
12
+ webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
13
+ }
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallHuman = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const menu_1 = require("./menu");
6
+ const LANGUAGES = [
7
+ { name: "English (US)", value: "en" },
8
+ { name: "English (UK)", value: "en-gb" },
9
+ { name: "Spanish (Spain)", value: "es" },
10
+ { name: "Spanish (Latin America)", value: "es-mx" },
11
+ { name: "French (France)", value: "fr" },
12
+ { name: "French (Canada)", value: "fr-ca" },
13
+ { name: "Portuguese (Portugal)", value: "pt" },
14
+ { name: "Portuguese (Brazil)", value: "pt-br" },
15
+ { name: "German", value: "de" },
16
+ { name: "Italian", value: "it" },
17
+ { name: "Dutch", value: "nl" },
18
+ { name: "Polish", value: "pl" },
19
+ { name: "Swedish", value: "sv" },
20
+ { name: "Danish", value: "da" },
21
+ { name: "Norwegian", value: "nb" },
22
+ { name: "Finnish", value: "fi" },
23
+ { name: "Catalan", value: "ca" },
24
+ { name: "Czech", value: "cs" },
25
+ { name: "Turkish", value: "tr" },
26
+ ];
27
+ const label = {
28
+ displayName: "Label",
29
+ name: "label",
30
+ type: "string",
31
+ default: "",
32
+ required: true,
33
+ placeholder: "Confirm",
34
+ description: 'What is offered: read as "Press 1 or say Confirm". People can press the key or answer in their own words.',
35
+ };
36
+ const answerId = {
37
+ displayName: "ID",
38
+ name: "id",
39
+ type: "string",
40
+ default: "",
41
+ placeholder: "confirm",
42
+ description: "Optional. Your identifier for this answer, returned as option_id in the result. If empty: answer_1, answer_2… Not used when the option has sub-options.",
43
+ };
44
+ const reply = {
45
+ displayName: "Reply",
46
+ name: "reply",
47
+ type: "string",
48
+ default: "",
49
+ placeholder: "Perfect, see you tonight!",
50
+ description: "Optional. Read right after the person chooses this option, then the call ends. Leave empty when the option has sub-options.",
51
+ };
52
+ /** Sub-options make this option a submenu (one level only). Your plan caps the answers per call. */
53
+ const subOptions = (values) => ({
54
+ displayName: "Sub-options",
55
+ name: "subOptions",
56
+ type: "fixedCollection",
57
+ typeOptions: { multipleValues: true, sortable: true },
58
+ placeholder: "Add Sub-option",
59
+ default: {},
60
+ description: "Turn this option into a submenu. Pressing 0 or saying “back” returns to the previous menu.",
61
+ options: [{ name: "option", displayName: "Sub-option", values }],
62
+ });
63
+ class CallHuman {
64
+ description = {
65
+ displayName: "CallHuman",
66
+ name: "callHuman",
67
+ icon: { light: "file:callhuman.svg", dark: "file:callhuman.dark.svg" },
68
+ group: ["transform"],
69
+ version: 1,
70
+ subtitle: '={{$parameter["operation"] === "cancelCall" ? "Cancel " + $parameter["callId"] : "Call " + $parameter["phone"]}}',
71
+ description: "Call a person, read a message and continue down the branch of the option they choose",
72
+ defaults: { name: "Call and wait for answer" },
73
+ usableAsTool: true,
74
+ inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
75
+ // One output per final option (submenus included) + "No answer"; "Done" + "No answer" without options.
76
+ outputs: `={{(${menu_1.configuredOutputs})($parameter)}}`,
77
+ credentials: [{ name: "callHumanApi", required: true }],
78
+ // Resume webhook, like n8n's Wait node: CallHuman POSTs the result to $execution.resumeUrl.
79
+ webhooks: [
80
+ {
81
+ name: "default",
82
+ httpMethod: "POST",
83
+ responseMode: "onReceived",
84
+ responseData: "",
85
+ path: "",
86
+ restartWebhook: true,
87
+ },
88
+ ],
89
+ properties: [
90
+ {
91
+ displayName: "Operation",
92
+ name: "operation",
93
+ type: "options",
94
+ noDataExpression: true,
95
+ options: [
96
+ { name: "Call and Wait for Answer", value: "callAndWait", action: "Call a person and wait for the answer" },
97
+ { name: "Cancel Call", value: "cancelCall", action: "Cancel a queued or active call" },
98
+ ],
99
+ default: "callAndWait",
100
+ },
101
+ {
102
+ displayName: "Call ID",
103
+ name: "callId",
104
+ type: "string",
105
+ default: "",
106
+ required: true,
107
+ placeholder: "call_x9f2k",
108
+ description: "ID of the queued or in-progress call to cancel (stops pending retries immediately)",
109
+ displayOptions: { show: { operation: ["cancelCall"] } },
110
+ },
111
+ {
112
+ displayName: "Phone Number",
113
+ name: "phone",
114
+ type: "string",
115
+ default: "",
116
+ required: true,
117
+ placeholder: "+34600111222",
118
+ description: "International format, with + and country code",
119
+ displayOptions: { show: { operation: ["callAndWait"] } },
120
+ },
121
+ {
122
+ displayName: "Message",
123
+ name: "message",
124
+ type: "string",
125
+ typeOptions: { rows: 3 },
126
+ default: "",
127
+ required: true,
128
+ placeholder: "Hi! This is La Plaza about your table for 4 tonight at 8:30 pm.",
129
+ description: "What we read when the person answers",
130
+ displayOptions: { show: { operation: ["callAndWait"] } },
131
+ },
132
+ {
133
+ displayName: "Language",
134
+ name: "language",
135
+ type: "options",
136
+ options: LANGUAGES,
137
+ default: "en",
138
+ description: "The language the message and the menus are read in",
139
+ displayOptions: { show: { operation: ["callAndWait"] } },
140
+ },
141
+ {
142
+ displayName: "Options",
143
+ name: "options",
144
+ type: "fixedCollection",
145
+ typeOptions: { multipleValues: true, sortable: true },
146
+ placeholder: "Add Option",
147
+ default: {},
148
+ description: "Each option gets its own output. Your plan sets how many answers a call can offer (submenus from 3). Leave empty for a one-way message (e.g. a code): outputs Done and No answer.",
149
+ displayOptions: { show: { operation: ["callAndWait"] } },
150
+ options: [
151
+ {
152
+ name: "option",
153
+ displayName: "Option",
154
+ values: [label, answerId, reply, subOptions([label, answerId, reply])],
155
+ },
156
+ ],
157
+ },
158
+ {
159
+ displayName: "Additional Fields",
160
+ name: "additionalFields",
161
+ type: "collection",
162
+ placeholder: "Add Field",
163
+ default: {},
164
+ displayOptions: { show: { operation: ["callAndWait"] } },
165
+ options: [
166
+ {
167
+ displayName: "Retries",
168
+ name: "retries",
169
+ type: "number",
170
+ typeOptions: { minValue: 0, maxValue: 5 },
171
+ default: 2,
172
+ description: "How many more times we call if nobody answers, it's busy, rejected or voicemail. Default: 2 with options, 0 without.",
173
+ },
174
+ {
175
+ displayName: "Retry Delay (Seconds)",
176
+ name: "retryDelaySeconds",
177
+ type: "number",
178
+ typeOptions: { minValue: 60, maxValue: 3600 },
179
+ default: 300,
180
+ description: "Wait between the end of one attempt and the next",
181
+ },
182
+ {
183
+ displayName: "Metadata",
184
+ name: "metadata",
185
+ type: "json",
186
+ default: "{}",
187
+ description: "Any JSON object (max 4 KB) returned unchanged in the result, e.g. your booking ID",
188
+ },
189
+ ],
190
+ },
191
+ ],
192
+ };
193
+ // The resume webhook lives only while one execution waits, and n8n creates and removes it
194
+ // itself: there is nothing to register with CallHuman, so these hooks have nothing to do.
195
+ webhookMethods = {
196
+ default: {
197
+ async checkExists() {
198
+ return true;
199
+ },
200
+ async create() {
201
+ return true;
202
+ },
203
+ async delete() {
204
+ return true;
205
+ },
206
+ },
207
+ };
208
+ async execute() {
209
+ const operation = String(this.getNodeParameter("operation", 0, "callAndWait"));
210
+ const credentials = await this.getCredentials("callHumanApi");
211
+ const baseUrl = String(credentials.baseUrl ?? "https://api.callhuman.es").replace(/\/$/, "");
212
+ if (operation === "cancelCall") {
213
+ const items = this.getInputData();
214
+ const canceled = [];
215
+ for (let i = 0; i < items.length; i++) {
216
+ const callId = String(this.getNodeParameter("callId", i)).trim();
217
+ if (!/^call_[A-Za-z0-9]+$/.test(callId)) {
218
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid Call ID "${callId}". Expected an ID like call_x9f2k.`, { itemIndex: i });
219
+ }
220
+ try {
221
+ const result = (await this.helpers.httpRequestWithAuthentication.call(this, "callHumanApi", {
222
+ method: "POST",
223
+ url: `${baseUrl}/v1/calls/${encodeURIComponent(callId)}/cancel`,
224
+ json: true,
225
+ }));
226
+ canceled.push({ json: result, pairedItem: { item: i } });
227
+ }
228
+ catch (error) {
229
+ throw apiError(this, error);
230
+ }
231
+ }
232
+ return [canceled];
233
+ }
234
+ // One call per execution (the workflow waits for it), using the first item.
235
+ const parameters = { operation, options: this.getNodeParameter("options", 0, {}) };
236
+ const outputs = (0, menu_1.configuredOutputs)(parameters).map(() => []);
237
+ let options;
238
+ try {
239
+ options = (0, menu_1.toApiOptions)(parameters);
240
+ }
241
+ catch (error) {
242
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message);
243
+ }
244
+ const extra = this.getNodeParameter("additionalFields", 0, {});
245
+ let metadata = {};
246
+ if (extra.metadata) {
247
+ try {
248
+ metadata = typeof extra.metadata === "string" ? JSON.parse(extra.metadata) : extra.metadata;
249
+ }
250
+ catch {
251
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Metadata must be a JSON object, e.g. {\"booking_id\": \"bk_1042\"}");
252
+ }
253
+ }
254
+ // Carries this execution's resume token: only this execution can be resumed with it.
255
+ const webhookUrl = String(this.evaluateExpression("{{ $execution.resumeUrl }}", 0));
256
+ if (!webhookUrl.startsWith("https://") && baseUrl === "https://api.callhuman.es") {
257
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), "CallHuman can't reach this n8n to send the answer back: its webhook URL isn't public https.", { description: `Current URL: ${webhookUrl.split("?")[0]}. Use n8n Cloud, or set WEBHOOK_URL to a public https address (e.g. a tunnel) for self-hosted n8n.` });
258
+ }
259
+ const body = {
260
+ to: String(this.getNodeParameter("phone", 0)).replace(/[\s().-]/g, ""),
261
+ message: this.getNodeParameter("message", 0),
262
+ language: this.getNodeParameter("language", 0),
263
+ webhook_url: webhookUrl,
264
+ metadata,
265
+ };
266
+ if (options.length)
267
+ body.options = options;
268
+ if (extra.retries !== undefined)
269
+ body.retries = extra.retries;
270
+ if (extra.retryDelaySeconds !== undefined)
271
+ body.retry_delay_seconds = extra.retryDelaySeconds;
272
+ let created;
273
+ try {
274
+ created = await this.helpers.httpRequestWithAuthentication.call(this, "callHumanApi", {
275
+ method: "POST",
276
+ url: `${baseUrl}/v1/calls`,
277
+ body,
278
+ json: true,
279
+ });
280
+ }
281
+ catch (error) {
282
+ throw apiError(this, error);
283
+ }
284
+ // Wait for the result. If it never comes (e.g. n8n was unreachable), continue via "No answer".
285
+ const retries = extra.retries ?? (options.length ? 2 : 0);
286
+ const delay = extra.retryDelaySeconds ?? 300;
287
+ const waitSeconds = retries * delay + 15 * 60 + 3 * 60 * 60;
288
+ await this.putExecutionToWait(new Date(Date.now() + waitSeconds * 1000));
289
+ outputs[outputs.length - 1] = [
290
+ { json: { id: created.id, status: "timeout", option_id: null, option_label: null, answer_method: null, answer_transcript: null, metadata }, pairedItem: { item: 0 } },
291
+ ];
292
+ return outputs;
293
+ }
294
+ async webhook() {
295
+ const body = this.getBodyData();
296
+ if (typeof body.id !== "string" || !/^call_[A-Za-z0-9]+$/.test(body.id)) {
297
+ return { webhookResponse: { ok: false, error: "missing call id" } };
298
+ }
299
+ // Don't trust the body: read the result from the API with this node's API key.
300
+ const credentials = await this.getCredentials("callHumanApi");
301
+ const baseUrl = String(credentials.baseUrl ?? "https://api.callhuman.es").replace(/\/$/, "");
302
+ let result;
303
+ try {
304
+ result = await this.helpers.httpRequestWithAuthentication.call(this, "callHumanApi", {
305
+ method: "GET",
306
+ url: `${baseUrl}/v1/calls/${body.id}`,
307
+ json: true,
308
+ });
309
+ }
310
+ catch {
311
+ return { webhookResponse: { ok: false, error: "unknown call" } };
312
+ }
313
+ if (!menu_1.FINAL_STATUSES.includes(result.status))
314
+ return { webhookResponse: { ok: true, waiting: true } };
315
+ const parameters = { options: this.getNodeParameter("options", {}) };
316
+ const outputs = (0, menu_1.configuredOutputs)(parameters).map(() => []);
317
+ outputs[(0, menu_1.outputIndex)(parameters, result)] = [{ json: result, pairedItem: { item: 0 } }];
318
+ return { workflowData: outputs, webhookResponse: { ok: true } };
319
+ }
320
+ }
321
+ exports.CallHuman = CallHuman;
322
+ /** API errors keep CallHuman's message (it says how to fix it). */
323
+ function apiError(ctx, error) {
324
+ const e = error;
325
+ const apiErrorBody = e.response?.body?.error;
326
+ return new n8n_workflow_1.NodeApiError(ctx.getNode(), error, {
327
+ message: apiErrorBody?.message ?? "CallHuman couldn't place the call",
328
+ description: apiErrorBody?.code ? `Error code: ${apiErrorBody.code} — https://www.callhuman.es/docs/errors#${apiErrorBody.code}` : undefined,
329
+ });
330
+ }
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" fill="none">
2
+ <rect x="9" y="3" width="22" height="34" rx="8" fill="#c6b5fb" stroke="#e9e4f5" stroke-width="2.2"/>
3
+ <rect x="12.5" y="8" width="15" height="21" rx="4.5" fill="#ede7fe" stroke="#e9e4f5" stroke-width="2"/>
4
+ <circle cx="17" cy="16" r="1.4" fill="#e9e4f5"/>
5
+ <circle cx="23" cy="16" r="1.4" fill="#e9e4f5"/>
6
+ <ellipse cx="14.8" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
7
+ <ellipse cx="25.2" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
8
+ <path d="M17.6 20.2q2.4 2.2 4.8 0" stroke="#e9e4f5" stroke-width="1.8" stroke-linecap="round"/>
9
+ <circle cx="20" cy="33" r="1.4" fill="#fff" stroke="#e9e4f5" stroke-width="1.4"/>
10
+ </svg>
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" fill="none">
2
+ <rect x="9" y="3" width="22" height="34" rx="8" fill="#c6b5fb" stroke="#3b3550" stroke-width="2.2"/>
3
+ <rect x="12.5" y="8" width="15" height="21" rx="4.5" fill="#ede7fe" stroke="#3b3550" stroke-width="2"/>
4
+ <circle cx="17" cy="16" r="1.4" fill="#3b3550"/>
5
+ <circle cx="23" cy="16" r="1.4" fill="#3b3550"/>
6
+ <ellipse cx="14.8" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
7
+ <ellipse cx="25.2" cy="19.6" rx="1.6" ry="1" fill="#ffb385"/>
8
+ <path d="M17.6 20.2q2.4 2.2 4.8 0" stroke="#3b3550" stroke-width="1.8" stroke-linecap="round"/>
9
+ <circle cx="20" cy="33" r="1.4" fill="#fff" stroke="#3b3550" stroke-width="1.4"/>
10
+ </svg>
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Pure logic of the CallHuman node: outputs, conversion to the API body and routing.
3
+ * Same rules as the API (docs/05): max 9 options per menu, one submenu level, reply xor
4
+ * sub-options, and every answer has an id (D-068). The plan's cap on answers per call is
5
+ * checked by the API (its message says how to fix it).
6
+ */
7
+ /** How the options look in the node parameters (fixedCollection, nested). */
8
+ export type ParamOption = {
9
+ id?: string;
10
+ label?: string;
11
+ reply?: string;
12
+ subOptions?: {
13
+ option?: ParamOption[];
14
+ };
15
+ };
16
+ export type NodeParameters = {
17
+ operation?: string;
18
+ options?: {
19
+ option?: ParamOption[];
20
+ };
21
+ };
22
+ export type ApiOption = {
23
+ id?: string;
24
+ label: string;
25
+ reply?: string;
26
+ options?: ApiOption[];
27
+ };
28
+ export declare const NO_ANSWER = "No answer";
29
+ export declare const DONE = "Done";
30
+ /**
31
+ * Output list from the node parameters: one per answer (named by its label, wherever it sits
32
+ * in the menus) plus "No answer"; without options, "Done" + "No answer".
33
+ * Must stay self-contained (no imports, no outer variables): n8n serializes it into the
34
+ * `outputs` expression so the editor redraws the outputs as options change.
35
+ */
36
+ export declare function configuredOutputs(parameters: NodeParameters): {
37
+ type: string;
38
+ displayName: string;
39
+ }[];
40
+ /** The id of each answer, in output order: the one typed in the node, or "answer_<n>". */
41
+ export declare function answerIds(parameters: NodeParameters): string[];
42
+ /** Converts the parameters to the API `options`, or throws with the same messages as the API. */
43
+ export declare function toApiOptions(parameters: NodeParameters): ApiOption[];
44
+ export type CallResult = {
45
+ id: string;
46
+ status: string;
47
+ option_id: string | null;
48
+ option_label: string | null;
49
+ answer_method?: "keypad" | "voice" | null;
50
+ answer_transcript?: string | null;
51
+ metadata: unknown;
52
+ };
53
+ export declare const FINAL_STATUSES: string[];
54
+ /**
55
+ * Which output a finished call goes to: the chosen answer (by its id), "Done" for an answered
56
+ * one-way message, and "No answer" for everything else (not answered, failed, canceled, or
57
+ * answered without choosing anything).
58
+ */
59
+ export declare function outputIndex(parameters: NodeParameters, result: CallResult): number;