n8n-nodes-callhuman 0.1.0 → 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/README.md CHANGED
@@ -39,9 +39,13 @@ You need an active CallHuman plan and a phone number to place calls.
39
39
  Each branch receives the result:
40
40
 
41
41
  ```json
42
- { "id": "call_x9f2k", "status": "answered", "option_id": "change_time", "option_label": "Change time", "metadata": { "booking_id": "bk_1042" } }
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
43
  ```
44
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
+
45
49
  <br clear="right" />
46
50
 
47
51
  ## Templates
@@ -67,7 +67,7 @@ class CallHuman {
67
67
  icon: { light: "file:callhuman.svg", dark: "file:callhuman.dark.svg" },
68
68
  group: ["transform"],
69
69
  version: 1,
70
- subtitle: '={{"Call " + $parameter["phone"]}}',
70
+ subtitle: '={{$parameter["operation"] === "cancelCall" ? "Cancel " + $parameter["callId"] : "Call " + $parameter["phone"]}}',
71
71
  description: "Call a person, read a message and continue down the branch of the option they choose",
72
72
  defaults: { name: "Call and wait for answer" },
73
73
  usableAsTool: true,
@@ -92,9 +92,22 @@ class CallHuman {
92
92
  name: "operation",
93
93
  type: "options",
94
94
  noDataExpression: true,
95
- options: [{ name: "Call and Wait for Answer", value: "callAndWait", action: "Call a person and wait for the answer" }],
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
+ ],
96
99
  default: "callAndWait",
97
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
+ },
98
111
  {
99
112
  displayName: "Phone Number",
100
113
  name: "phone",
@@ -103,6 +116,7 @@ class CallHuman {
103
116
  required: true,
104
117
  placeholder: "+34600111222",
105
118
  description: "International format, with + and country code",
119
+ displayOptions: { show: { operation: ["callAndWait"] } },
106
120
  },
107
121
  {
108
122
  displayName: "Message",
@@ -113,6 +127,7 @@ class CallHuman {
113
127
  required: true,
114
128
  placeholder: "Hi! This is La Plaza about your table for 4 tonight at 8:30 pm.",
115
129
  description: "What we read when the person answers",
130
+ displayOptions: { show: { operation: ["callAndWait"] } },
116
131
  },
117
132
  {
118
133
  displayName: "Language",
@@ -121,6 +136,7 @@ class CallHuman {
121
136
  options: LANGUAGES,
122
137
  default: "en",
123
138
  description: "The language the message and the menus are read in",
139
+ displayOptions: { show: { operation: ["callAndWait"] } },
124
140
  },
125
141
  {
126
142
  displayName: "Options",
@@ -130,6 +146,7 @@ class CallHuman {
130
146
  placeholder: "Add Option",
131
147
  default: {},
132
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"] } },
133
150
  options: [
134
151
  {
135
152
  name: "option",
@@ -144,6 +161,7 @@ class CallHuman {
144
161
  type: "collection",
145
162
  placeholder: "Add Field",
146
163
  default: {},
164
+ displayOptions: { show: { operation: ["callAndWait"] } },
147
165
  options: [
148
166
  {
149
167
  displayName: "Retries",
@@ -188,8 +206,33 @@ class CallHuman {
188
206
  },
189
207
  };
190
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
+ }
191
234
  // One call per execution (the workflow waits for it), using the first item.
192
- const parameters = { options: this.getNodeParameter("options", 0, {}) };
235
+ const parameters = { operation, options: this.getNodeParameter("options", 0, {}) };
193
236
  const outputs = (0, menu_1.configuredOutputs)(parameters).map(() => []);
194
237
  let options;
195
238
  try {
@@ -210,8 +253,6 @@ class CallHuman {
210
253
  }
211
254
  // Carries this execution's resume token: only this execution can be resumed with it.
212
255
  const webhookUrl = String(this.evaluateExpression("{{ $execution.resumeUrl }}", 0));
213
- const credentials = await this.getCredentials("callHumanApi");
214
- const baseUrl = String(credentials.baseUrl ?? "https://api.callhuman.es").replace(/\/$/, "");
215
256
  if (!webhookUrl.startsWith("https://") && baseUrl === "https://api.callhuman.es") {
216
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.` });
217
258
  }
@@ -245,7 +286,9 @@ class CallHuman {
245
286
  const delay = extra.retryDelaySeconds ?? 300;
246
287
  const waitSeconds = retries * delay + 15 * 60 + 3 * 60 * 60;
247
288
  await this.putExecutionToWait(new Date(Date.now() + waitSeconds * 1000));
248
- outputs[outputs.length - 1] = [{ json: { id: created.id, status: "timeout", option_id: null, option_label: null, metadata }, pairedItem: { item: 0 } }];
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
+ ];
249
292
  return outputs;
250
293
  }
251
294
  async webhook() {
@@ -14,6 +14,7 @@ export type ParamOption = {
14
14
  };
15
15
  };
16
16
  export type NodeParameters = {
17
+ operation?: string;
17
18
  options?: {
18
19
  option?: ParamOption[];
19
20
  };
@@ -33,7 +34,7 @@ export declare const DONE = "Done";
33
34
  * `outputs` expression so the editor redraws the outputs as options change.
34
35
  */
35
36
  export declare function configuredOutputs(parameters: NodeParameters): {
36
- type: "main";
37
+ type: string;
37
38
  displayName: string;
38
39
  }[];
39
40
  /** The id of each answer, in output order: the one typed in the node, or "answer_<n>". */
@@ -45,6 +46,8 @@ export type CallResult = {
45
46
  status: string;
46
47
  option_id: string | null;
47
48
  option_label: string | null;
49
+ answer_method?: "keypad" | "voice" | null;
50
+ answer_transcript?: string | null;
48
51
  metadata: unknown;
49
52
  };
50
53
  export declare const FINAL_STATUSES: string[];
@@ -20,6 +20,9 @@ exports.DONE = "Done";
20
20
  * `outputs` expression so the editor redraws the outputs as options change.
21
21
  */
22
22
  function configuredOutputs(parameters) {
23
+ if (parameters?.operation === "cancelCall") {
24
+ return [{ type: "main", displayName: "Done" }];
25
+ }
23
26
  const outputs = [];
24
27
  const walk = (options) => {
25
28
  (options ?? []).forEach((option) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-callhuman",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "n8n node for CallHuman: call a person, read a message and continue down the branch of the option they choose (keypress or voice).",
5
5
  "license": "MIT",
6
6
  "scripts": {