@zerodot/telegram 1.0.0 → 1.1.1
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 +34 -0
- package/dist/{index.mjs → index.cjs} +108 -106
- package/package.json +8 -7
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @zerodot/telegram
|
|
2
|
+
|
|
3
|
+
Send messages and files with a Telegram bot, and start a workflow when the bot gets a message or other update. Use it to build chat bots and notifications.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
In zerodot, go to **System > Nodes** and install **Telegram**.
|
|
8
|
+
|
|
9
|
+
Manual: install `@zerodot/telegram` where the web app and the worker run, and add it to `ZERODOT_NODE_PACKAGES`.
|
|
10
|
+
|
|
11
|
+
## Nodes
|
|
12
|
+
|
|
13
|
+
### Telegram (`telegram.bot`)
|
|
14
|
+
|
|
15
|
+
- **Message**: send, edit, delete, pin, unpin, send a chat action
|
|
16
|
+
- **Media**: send a photo, video, audio file, document, animation, sticker, location, or media group
|
|
17
|
+
- **Wait for response**: send a message and wait for an approval, a free text, or a form
|
|
18
|
+
- **Chat**: get information, get the administrators, get a member, leave, set the title, set the description
|
|
19
|
+
- **Callback and inline query**: answer
|
|
20
|
+
- **File**: get a file, and download it to binary data
|
|
21
|
+
|
|
22
|
+
Messages can have inline keyboards and reply keyboards. Files can come from a URL, a `file_id`, or binary data of the input.
|
|
23
|
+
|
|
24
|
+
### Telegram Trigger (`trigger.telegram`)
|
|
25
|
+
|
|
26
|
+
Starts a run on a bot update, for example a message, a callback query, or an inline query. You can accept updates only from some chats or users. The trigger sets the webhook of the bot, so Telegram must be able to reach your zerodot instance. A bot has one webhook only.
|
|
27
|
+
|
|
28
|
+
## Credential
|
|
29
|
+
|
|
30
|
+
**Telegram bot** (`telegram.bot`): `accessToken` from [@BotFather](https://t.me/BotFather), and an optional `baseUrl` for a local Bot API server. The token is secret.
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
AGPL-3.0-only
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
let _zerodot_node_sdk = require("@zerodot/node-sdk");
|
|
4
|
+
let node_crypto = require("node:crypto");
|
|
4
5
|
// src/api.ts
|
|
5
6
|
const TELEGRAM_CREDENTIAL = "telegram.bot";
|
|
6
7
|
const DEFAULT_BASE_URL = "https://api.telegram.org";
|
|
@@ -43,19 +44,19 @@ async function downloadTelegramFile(access, filePath, options) {
|
|
|
43
44
|
return bytes;
|
|
44
45
|
}
|
|
45
46
|
// src/icon.ts
|
|
46
|
-
const TELEGRAM_ICON = fileIcon(
|
|
47
|
+
const TELEGRAM_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../telegram.svg");
|
|
47
48
|
// src/credential.ts
|
|
48
49
|
const TIMEOUT_MS = 1e4;
|
|
49
50
|
const text = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
50
51
|
const telegramCredential = {
|
|
51
52
|
type: TELEGRAM_CREDENTIAL,
|
|
52
53
|
label: "Telegram bot",
|
|
53
|
-
fields: z.object({
|
|
54
|
-
accessToken: z.string().min(1).meta({ placeholder: "123456:ABC-DEF…" }),
|
|
55
|
-
baseUrl: z.url().optional().meta({ placeholder: "https://api.telegram.org" })
|
|
54
|
+
fields: zod.z.object({
|
|
55
|
+
accessToken: zod.z.string().min(1).meta({ placeholder: "123456:ABC-DEF…" }),
|
|
56
|
+
baseUrl: zod.z.url().optional().meta({ placeholder: "https://api.telegram.org" })
|
|
56
57
|
}),
|
|
57
58
|
secretFields: ["accessToken"],
|
|
58
|
-
icon: "
|
|
59
|
+
icon: "SentIcon",
|
|
59
60
|
iconUrl: TELEGRAM_ICON,
|
|
60
61
|
async test({ data }) {
|
|
61
62
|
const token = text(data.accessToken);
|
|
@@ -140,49 +141,49 @@ const CHAT_ACTIONS = [
|
|
|
140
141
|
"upload_video",
|
|
141
142
|
"upload_video_note"
|
|
142
143
|
];
|
|
143
|
-
const id = z.union([z.string(), z.number()]);
|
|
144
|
-
const button = z.object({
|
|
145
|
-
text: z.string(),
|
|
146
|
-
additionalFields: z.record(z.string(), z.unknown()).optional()
|
|
144
|
+
const id = zod.z.union([zod.z.string(), zod.z.number()]);
|
|
145
|
+
const button = zod.z.object({
|
|
146
|
+
text: zod.z.string(),
|
|
147
|
+
additionalFields: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
147
148
|
});
|
|
148
149
|
/** The "fixed collection" shape: rows.row.buttons. */
|
|
149
|
-
const keyboard = z.object({ rows: z.array(z.object({ row: z.object({ buttons: z.array(button) }) })).default([]) });
|
|
150
|
-
const mediaItem = z.object({
|
|
151
|
-
type: z.enum(["photo", "video"]),
|
|
152
|
-
media: z.string(),
|
|
153
|
-
additionalFields: z.object({
|
|
154
|
-
caption: z.string(),
|
|
155
|
-
parse_mode: z.enum([
|
|
150
|
+
const keyboard = zod.z.object({ rows: zod.z.array(zod.z.object({ row: zod.z.object({ buttons: zod.z.array(button) }) })).default([]) });
|
|
151
|
+
const mediaItem = zod.z.object({
|
|
152
|
+
type: zod.z.enum(["photo", "video"]),
|
|
153
|
+
media: zod.z.string(),
|
|
154
|
+
additionalFields: zod.z.object({
|
|
155
|
+
caption: zod.z.string(),
|
|
156
|
+
parse_mode: zod.z.enum([
|
|
156
157
|
"Markdown",
|
|
157
158
|
"MarkdownV2",
|
|
158
159
|
"HTML"
|
|
159
160
|
])
|
|
160
161
|
}).partial().optional()
|
|
161
162
|
});
|
|
162
|
-
const additionalFields = z.object({
|
|
163
|
-
caption: z.string(),
|
|
164
|
-
disable_notification: z.boolean(),
|
|
165
|
-
disable_web_page_preview: z.boolean(),
|
|
166
|
-
duration: z.number(),
|
|
167
|
-
fileName: z.string(),
|
|
168
|
-
height: z.number(),
|
|
169
|
-
parse_mode: z.enum([
|
|
163
|
+
const additionalFields = zod.z.object({
|
|
164
|
+
caption: zod.z.string(),
|
|
165
|
+
disable_notification: zod.z.boolean(),
|
|
166
|
+
disable_web_page_preview: zod.z.boolean(),
|
|
167
|
+
duration: zod.z.number(),
|
|
168
|
+
fileName: zod.z.string(),
|
|
169
|
+
height: zod.z.number(),
|
|
170
|
+
parse_mode: zod.z.enum([
|
|
170
171
|
"Markdown",
|
|
171
172
|
"MarkdownV2",
|
|
172
173
|
"HTML"
|
|
173
174
|
]),
|
|
174
|
-
performer: z.string(),
|
|
175
|
-
reply_to_message_id: z.number(),
|
|
176
|
-
message_thread_id: z.number(),
|
|
177
|
-
title: z.string(),
|
|
178
|
-
thumb: z.string(),
|
|
179
|
-
width: z.number(),
|
|
180
|
-
cache_time: z.number(),
|
|
181
|
-
show_alert: z.boolean(),
|
|
182
|
-
text: z.string(),
|
|
183
|
-
url: z.string(),
|
|
184
|
-
mimeType: z.string()
|
|
185
|
-
}).partial().catchall(z.unknown());
|
|
175
|
+
performer: zod.z.string(),
|
|
176
|
+
reply_to_message_id: zod.z.number(),
|
|
177
|
+
message_thread_id: zod.z.number(),
|
|
178
|
+
title: zod.z.string(),
|
|
179
|
+
thumb: zod.z.string(),
|
|
180
|
+
width: zod.z.number(),
|
|
181
|
+
cache_time: zod.z.number(),
|
|
182
|
+
show_alert: zod.z.boolean(),
|
|
183
|
+
text: zod.z.string(),
|
|
184
|
+
url: zod.z.string(),
|
|
185
|
+
mimeType: zod.z.string()
|
|
186
|
+
}).partial().catchall(zod.z.unknown());
|
|
186
187
|
const forOperations = (...operations) => ({ showWhen: { operation: operations } });
|
|
187
188
|
const SEND_FILE = [
|
|
188
189
|
"sendPhoto",
|
|
@@ -207,8 +208,8 @@ const WITH_MARKUP = [
|
|
|
207
208
|
...SEND_FILE,
|
|
208
209
|
"sendLocation"
|
|
209
210
|
];
|
|
210
|
-
const telegramConfig = z.object({
|
|
211
|
-
resource: z.enum(RESOURCES).default("message").meta({
|
|
211
|
+
const telegramConfig = zod.z.object({
|
|
212
|
+
resource: zod.z.enum(RESOURCES).default("message").meta({
|
|
212
213
|
labels: {
|
|
213
214
|
message: "Message",
|
|
214
215
|
chat: "Chat",
|
|
@@ -222,7 +223,7 @@ const telegramConfig = z.object({
|
|
|
222
223
|
file: "Get a file that Telegram has"
|
|
223
224
|
}
|
|
224
225
|
}),
|
|
225
|
-
operation: z.enum(OPERATIONS).default("sendMessage").meta({
|
|
226
|
+
operation: zod.z.enum(OPERATIONS).default("sendMessage").meta({
|
|
226
227
|
labels: {
|
|
227
228
|
sendMessage: "Send Message",
|
|
228
229
|
editMessageText: "Edit Message Text",
|
|
@@ -300,7 +301,7 @@ const telegramConfig = z.object({
|
|
|
300
301
|
description: "Unique identifier of the target chat, or @channelusername"
|
|
301
302
|
}),
|
|
302
303
|
messageId: id.optional().meta(forOperations("editMessageText", "deleteMessage", "pinChatMessage", "unpinChatMessage")),
|
|
303
|
-
messageType: z.enum(["message", "inlineMessage"]).optional().meta({
|
|
304
|
+
messageType: zod.z.enum(["message", "inlineMessage"]).optional().meta({
|
|
304
305
|
...forOperations("editMessageText"),
|
|
305
306
|
labels: {
|
|
306
307
|
message: "Message",
|
|
@@ -311,39 +312,39 @@ const telegramConfig = z.object({
|
|
|
311
312
|
inlineMessage: "A message that was sent through inline mode"
|
|
312
313
|
}
|
|
313
314
|
}),
|
|
314
|
-
inlineMessageId: z.string().optional().meta(forOperations("editMessageText")),
|
|
315
|
+
inlineMessageId: zod.z.string().optional().meta(forOperations("editMessageText")),
|
|
315
316
|
userId: id.optional().meta(forOperations("member")),
|
|
316
|
-
title: z.string().optional().meta(forOperations("setTitle")),
|
|
317
|
-
description: z.string().optional().meta(forOperations("setDescription")),
|
|
318
|
-
queryId: z.string().optional().meta(forOperations("answerQuery", "answerInlineQuery")),
|
|
319
|
-
results: z.string().optional().meta({
|
|
317
|
+
title: zod.z.string().optional().meta(forOperations("setTitle")),
|
|
318
|
+
description: zod.z.string().optional().meta(forOperations("setDescription")),
|
|
319
|
+
queryId: zod.z.string().optional().meta(forOperations("answerQuery", "answerInlineQuery")),
|
|
320
|
+
results: zod.z.string().optional().meta({
|
|
320
321
|
...forOperations("answerInlineQuery"),
|
|
321
322
|
description: "A JSON array of results for the inline query"
|
|
322
323
|
}),
|
|
323
|
-
fileId: z.string().optional().meta({ showWhen: {
|
|
324
|
+
fileId: zod.z.string().optional().meta({ showWhen: {
|
|
324
325
|
resource: ["file"],
|
|
325
326
|
operation: ["get"]
|
|
326
327
|
} }),
|
|
327
|
-
download: z.boolean().default(false).meta({
|
|
328
|
+
download: zod.z.boolean().default(false).meta({
|
|
328
329
|
showWhen: {
|
|
329
330
|
resource: ["file"],
|
|
330
331
|
operation: ["get"]
|
|
331
332
|
},
|
|
332
333
|
description: "Add the file as binary data to the output"
|
|
333
334
|
}),
|
|
334
|
-
binaryData: z.boolean().default(false).meta({
|
|
335
|
+
binaryData: zod.z.boolean().default(false).meta({
|
|
335
336
|
...forOperations(...SEND_FILE),
|
|
336
337
|
description: "Upload the binary data of the input instead of a URL or a file_id"
|
|
337
338
|
}),
|
|
338
|
-
binaryPropertyName: z.string().default("data").meta({
|
|
339
|
+
binaryPropertyName: zod.z.string().default("data").meta({
|
|
339
340
|
showWhen: { binaryData: [true] },
|
|
340
341
|
description: "The property of `binary` in the input that holds the file"
|
|
341
342
|
}),
|
|
342
|
-
message: z.string().optional().meta({
|
|
343
|
+
message: zod.z.string().optional().meta({
|
|
343
344
|
...forOperations("sendAndWait"),
|
|
344
345
|
description: "The message to send, with the buttons"
|
|
345
346
|
}),
|
|
346
|
-
responseType: z.enum([
|
|
347
|
+
responseType: zod.z.enum([
|
|
347
348
|
"approval",
|
|
348
349
|
"freeText",
|
|
349
350
|
"customForm"
|
|
@@ -361,43 +362,43 @@ const telegramConfig = z.object({
|
|
|
361
362
|
customForm: "The user fills in a form with the fields that you set"
|
|
362
363
|
}
|
|
363
364
|
}),
|
|
364
|
-
approvalOptions: z.object({
|
|
365
|
-
approvalType: z.enum(["single", "double"]).default("single"),
|
|
366
|
-
approveLabel: z.string().default("Approve"),
|
|
367
|
-
disapproveLabel: z.string().default("Decline")
|
|
365
|
+
approvalOptions: zod.z.object({
|
|
366
|
+
approvalType: zod.z.enum(["single", "double"]).default("single"),
|
|
367
|
+
approveLabel: zod.z.string().default("Approve"),
|
|
368
|
+
disapproveLabel: zod.z.string().default("Decline")
|
|
368
369
|
}).partial().optional().meta({ showWhen: {
|
|
369
370
|
operation: ["sendAndWait"],
|
|
370
371
|
responseType: ["approval"]
|
|
371
372
|
} }),
|
|
372
|
-
formFields: z.array(z.object({
|
|
373
|
-
fieldLabel: z.string(),
|
|
374
|
-
fieldType: z.enum(FORM_FIELD_TYPES).optional(),
|
|
375
|
-
placeholder: z.string().optional(),
|
|
376
|
-
requiredField: z.boolean().optional(),
|
|
377
|
-
fieldOptions: z.object({ values: z.array(z.object({ option: z.string() })) }).optional()
|
|
373
|
+
formFields: zod.z.array(zod.z.object({
|
|
374
|
+
fieldLabel: zod.z.string(),
|
|
375
|
+
fieldType: zod.z.enum(_zerodot_node_sdk.FORM_FIELD_TYPES).optional(),
|
|
376
|
+
placeholder: zod.z.string().optional(),
|
|
377
|
+
requiredField: zod.z.boolean().optional(),
|
|
378
|
+
fieldOptions: zod.z.object({ values: zod.z.array(zod.z.object({ option: zod.z.string() })) }).optional()
|
|
378
379
|
})).optional().meta({ showWhen: {
|
|
379
380
|
operation: ["sendAndWait"],
|
|
380
381
|
responseType: ["customForm"]
|
|
381
382
|
} }),
|
|
382
|
-
options: z.object({
|
|
383
|
-
messageButtonLabel: z.string(),
|
|
384
|
-
responseFormTitle: z.string(),
|
|
385
|
-
responseFormDescription: z.string(),
|
|
386
|
-
responseFormButtonLabel: z.string(),
|
|
387
|
-
limitWaitTimeHours: z.number().min(.01).max(720)
|
|
383
|
+
options: zod.z.object({
|
|
384
|
+
messageButtonLabel: zod.z.string(),
|
|
385
|
+
responseFormTitle: zod.z.string(),
|
|
386
|
+
responseFormDescription: zod.z.string(),
|
|
387
|
+
responseFormButtonLabel: zod.z.string(),
|
|
388
|
+
limitWaitTimeHours: zod.z.number().min(.01).max(720)
|
|
388
389
|
}).partial().optional().meta({
|
|
389
390
|
...forOperations("sendAndWait"),
|
|
390
391
|
description: "limitWaitTimeHours: how long to wait for an answer. Default 168 (7 days)."
|
|
391
392
|
}),
|
|
392
|
-
text: z.string().optional().meta({
|
|
393
|
+
text: zod.z.string().optional().meta({
|
|
393
394
|
...forOperations("sendMessage", "editMessageText"),
|
|
394
395
|
ui: "textarea"
|
|
395
396
|
}),
|
|
396
|
-
file: z.string().optional().meta({
|
|
397
|
+
file: zod.z.string().optional().meta({
|
|
397
398
|
...forOperations(...SEND_FILE),
|
|
398
399
|
description: "A public URL, or the file_id of a file that Telegram has"
|
|
399
400
|
}),
|
|
400
|
-
action: z.enum(CHAT_ACTIONS).optional().meta({
|
|
401
|
+
action: zod.z.enum(CHAT_ACTIONS).optional().meta({
|
|
401
402
|
...forOperations("sendChatAction"),
|
|
402
403
|
labels: {
|
|
403
404
|
typing: "Typing a Message",
|
|
@@ -424,10 +425,10 @@ const telegramConfig = z.object({
|
|
|
424
425
|
upload_video_note: "Show that the bot sends a round video"
|
|
425
426
|
}
|
|
426
427
|
}),
|
|
427
|
-
latitude: z.number().optional().meta(forOperations("sendLocation")),
|
|
428
|
-
longitude: z.number().optional().meta(forOperations("sendLocation")),
|
|
429
|
-
media: z.object({ media: z.array(mediaItem) }).optional().meta(forOperations("sendMediaGroup")),
|
|
430
|
-
replyMarkup: z.enum([
|
|
428
|
+
latitude: zod.z.number().optional().meta(forOperations("sendLocation")),
|
|
429
|
+
longitude: zod.z.number().optional().meta(forOperations("sendLocation")),
|
|
430
|
+
media: zod.z.object({ media: zod.z.array(mediaItem) }).optional().meta(forOperations("sendMediaGroup")),
|
|
431
|
+
replyMarkup: zod.z.enum([
|
|
431
432
|
"none",
|
|
432
433
|
"inlineKeyboard",
|
|
433
434
|
"replyKeyboard",
|
|
@@ -453,21 +454,21 @@ const telegramConfig = z.object({
|
|
|
453
454
|
}),
|
|
454
455
|
inlineKeyboard: keyboard.optional().meta({ showWhen: { replyMarkup: ["inlineKeyboard"] } }),
|
|
455
456
|
replyKeyboard: keyboard.optional().meta({ showWhen: { replyMarkup: ["replyKeyboard"] } }),
|
|
456
|
-
replyKeyboardOptions: z.object({
|
|
457
|
-
resize_keyboard: z.boolean(),
|
|
458
|
-
one_time_keyboard: z.boolean(),
|
|
459
|
-
selective: z.boolean()
|
|
457
|
+
replyKeyboardOptions: zod.z.object({
|
|
458
|
+
resize_keyboard: zod.z.boolean(),
|
|
459
|
+
one_time_keyboard: zod.z.boolean(),
|
|
460
|
+
selective: zod.z.boolean()
|
|
460
461
|
}).partial().optional().meta({ showWhen: { replyMarkup: ["replyKeyboard"] } }),
|
|
461
|
-
replyKeyboardRemove: z.object({
|
|
462
|
-
remove_keyboard: z.boolean(),
|
|
463
|
-
selective: z.boolean()
|
|
462
|
+
replyKeyboardRemove: zod.z.object({
|
|
463
|
+
remove_keyboard: zod.z.boolean(),
|
|
464
|
+
selective: zod.z.boolean()
|
|
464
465
|
}).partial().optional().meta({ showWhen: { replyMarkup: ["replyKeyboardRemove"] } }),
|
|
465
|
-
forceReply: z.object({
|
|
466
|
-
force_reply: z.boolean(),
|
|
467
|
-
selective: z.boolean()
|
|
466
|
+
forceReply: zod.z.object({
|
|
467
|
+
force_reply: zod.z.boolean(),
|
|
468
|
+
selective: zod.z.boolean()
|
|
468
469
|
}).partial().optional().meta({ showWhen: { replyMarkup: ["forceReply"] } }),
|
|
469
470
|
additionalFields: additionalFields.default({}).meta(forOperations(...WITH_ADDITIONAL)),
|
|
470
|
-
timeoutMs: z.number().int().min(1).max(3e5).default(3e4)
|
|
471
|
+
timeoutMs: zod.z.number().int().min(1).max(3e5).default(3e4)
|
|
471
472
|
}).superRefine((config, context) => {
|
|
472
473
|
if (!OPERATIONS_OF[config.resource].includes(config.operation)) context.addIssue({
|
|
473
474
|
code: "custom",
|
|
@@ -727,7 +728,7 @@ function uploadForm(body, property, file) {
|
|
|
727
728
|
form.set(property, new Blob([bytes], { type: file.mimeType }), file.fileName);
|
|
728
729
|
return form;
|
|
729
730
|
}
|
|
730
|
-
var node_default = defineNode({
|
|
731
|
+
var node_default = (0, _zerodot_node_sdk.defineNode)({
|
|
731
732
|
type: "telegram.bot",
|
|
732
733
|
label: "Telegram",
|
|
733
734
|
description: "Send messages and manage chats with a Telegram bot",
|
|
@@ -903,7 +904,7 @@ var node_default = defineNode({
|
|
|
903
904
|
}
|
|
904
905
|
}
|
|
905
906
|
],
|
|
906
|
-
icon: "
|
|
907
|
+
icon: "SentIcon",
|
|
907
908
|
iconUrl: TELEGRAM_ICON,
|
|
908
909
|
config: telegramConfig,
|
|
909
910
|
defaultConfig: {
|
|
@@ -940,7 +941,7 @@ var node_default = defineNode({
|
|
|
940
941
|
}
|
|
941
942
|
const { method, body } = buildRequest(config);
|
|
942
943
|
if (config.binaryData && config.resource === "message" && method !== "sendMessage") {
|
|
943
|
-
const file = readBinary(input, config.binaryPropertyName);
|
|
944
|
+
const file = (0, _zerodot_node_sdk.readBinary)(input, config.binaryPropertyName);
|
|
944
945
|
const fileName = config.additionalFields.fileName || file.fileName;
|
|
945
946
|
if (!fileName) throw new Error(`A file name is needed to ${config.operation}. Set "fileName" in additionalFields, or set it in the binary data`);
|
|
946
947
|
const property = fileProperty(config.operation);
|
|
@@ -959,12 +960,12 @@ var node_default = defineNode({
|
|
|
959
960
|
if (!filePath) throw new Error("Telegram did not give a file path");
|
|
960
961
|
const bytes = await downloadTelegramFile(access, filePath, options);
|
|
961
962
|
const fileName = filePath.split("/").pop() ?? "file";
|
|
962
|
-
const mimeType = config.additionalFields.mimeType || mimeTypeOf(fileName);
|
|
963
|
+
const mimeType = config.additionalFields.mimeType || (0, _zerodot_node_sdk.mimeTypeOf)(fileName);
|
|
963
964
|
return {
|
|
964
965
|
port: "out",
|
|
965
966
|
data: {
|
|
966
967
|
...answer,
|
|
967
|
-
binary: { data: toBinary(bytes, fileName, mimeType) }
|
|
968
|
+
binary: { data: (0, _zerodot_node_sdk.toBinary)(bytes, fileName, mimeType) }
|
|
968
969
|
}
|
|
969
970
|
};
|
|
970
971
|
}
|
|
@@ -974,8 +975,8 @@ var node_default = defineNode({
|
|
|
974
975
|
};
|
|
975
976
|
}
|
|
976
977
|
});
|
|
977
|
-
const triggerConfig = z.object({
|
|
978
|
-
updates: z.array(z.enum([
|
|
978
|
+
const triggerConfig = zod.z.object({
|
|
979
|
+
updates: zod.z.array(zod.z.enum([
|
|
979
980
|
"*",
|
|
980
981
|
"message",
|
|
981
982
|
"edited_message",
|
|
@@ -1013,11 +1014,11 @@ const triggerConfig = z.object({
|
|
|
1013
1014
|
shipping_query: "Trigger on new incoming shipping query. Only for invoices with a flexible price"
|
|
1014
1015
|
}
|
|
1015
1016
|
}),
|
|
1016
|
-
additionalFields: z.object({
|
|
1017
|
-
chatIds: z.string().meta({ description: "Only these chats, as ids with commas between" }),
|
|
1018
|
-
userIds: z.string().meta({ description: "Only these users, as ids with commas between" }),
|
|
1019
|
-
download: z.boolean().meta({ description: "Download the image or file of the message as binary data" }),
|
|
1020
|
-
imageSize: z.enum([
|
|
1017
|
+
additionalFields: zod.z.object({
|
|
1018
|
+
chatIds: zod.z.string().meta({ description: "Only these chats, as ids with commas between" }),
|
|
1019
|
+
userIds: zod.z.string().meta({ description: "Only these users, as ids with commas between" }),
|
|
1020
|
+
download: zod.z.boolean().meta({ description: "Download the image or file of the message as binary data" }),
|
|
1021
|
+
imageSize: zod.z.enum([
|
|
1021
1022
|
"small",
|
|
1022
1023
|
"medium",
|
|
1023
1024
|
"large",
|
|
@@ -1030,7 +1031,7 @@ const triggerConfig = z.object({
|
|
|
1030
1031
|
* Only characters A-Z, a-z, 0-9, _ and - are allowed, and it is at most 256 long.
|
|
1031
1032
|
*/
|
|
1032
1033
|
function telegramSecret(token) {
|
|
1033
|
-
return createHmac("sha256", token).update("zerodot-telegram-trigger").digest("base64url");
|
|
1034
|
+
return (0, node_crypto.createHmac)("sha256", token).update("zerodot-telegram-trigger").digest("base64url");
|
|
1034
1035
|
}
|
|
1035
1036
|
/** The last part of the webhook address is the token of the trigger. */
|
|
1036
1037
|
const tokenOf = (url) => new URL(url).pathname.split("/").filter(Boolean).pop() ?? "";
|
|
@@ -1039,7 +1040,7 @@ const ids = (list) => list ? list.split(",").map((id) => id.trim()) : void 0;
|
|
|
1039
1040
|
function checkTelegramUpdate(config, request) {
|
|
1040
1041
|
const given = Buffer.from(request.headers["x-telegram-bot-api-secret-token"] ?? "");
|
|
1041
1042
|
const wanted = Buffer.from(telegramSecret(request.token));
|
|
1042
|
-
if (given.byteLength !== wanted.byteLength || !timingSafeEqual(given, wanted)) return "forbidden";
|
|
1043
|
+
if (given.byteLength !== wanted.byteLength || !(0, node_crypto.timingSafeEqual)(given, wanted)) return "forbidden";
|
|
1043
1044
|
const parsed = triggerConfig.safeParse(config);
|
|
1044
1045
|
const { chatIds, userIds } = parsed.success ? parsed.data.additionalFields : {};
|
|
1045
1046
|
const body = request.body ?? {};
|
|
@@ -1105,13 +1106,13 @@ async function removeTelegramWebhook(access, options) {
|
|
|
1105
1106
|
});
|
|
1106
1107
|
}
|
|
1107
1108
|
// src/index.ts
|
|
1108
|
-
const nodes = [defineNode({
|
|
1109
|
+
const nodes = [(0, _zerodot_node_sdk.defineNode)({
|
|
1109
1110
|
type: "trigger.telegram",
|
|
1110
1111
|
label: "Telegram Trigger",
|
|
1111
1112
|
description: "Start the workflow on a Telegram bot update",
|
|
1112
1113
|
category: "trigger",
|
|
1113
1114
|
app: "Telegram",
|
|
1114
|
-
icon: "
|
|
1115
|
+
icon: "SentIcon",
|
|
1115
1116
|
iconUrl: TELEGRAM_ICON,
|
|
1116
1117
|
config: triggerConfig,
|
|
1117
1118
|
defaultConfig: {
|
|
@@ -1186,10 +1187,11 @@ const nodes = [defineNode({
|
|
|
1186
1187
|
port: "out",
|
|
1187
1188
|
data: {
|
|
1188
1189
|
...update,
|
|
1189
|
-
binary: { data: toBinary(bytes, fileName, file.mimeType) }
|
|
1190
|
+
binary: { data: (0, _zerodot_node_sdk.toBinary)(bytes, fileName, file.mimeType) }
|
|
1190
1191
|
}
|
|
1191
1192
|
};
|
|
1192
1193
|
}
|
|
1193
1194
|
}), node_default];
|
|
1194
1195
|
const credentialTypes = [telegramCredential];
|
|
1195
|
-
|
|
1196
|
+
exports.credentialTypes = credentialTypes;
|
|
1197
|
+
exports.nodes = nodes;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodot/telegram",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Send messages and files with a Telegram bot, and start a workflow when the bot gets a message or other update. Use it to build chat bots and notifications.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/zerodot-io/
|
|
8
|
+
"url": "git+https://github.com/zerodot-io/nodes.git",
|
|
9
9
|
"directory": "packages/telegram"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"zerodot-node-package"
|
|
13
13
|
],
|
|
14
14
|
"type": "module",
|
|
15
|
-
"main": "./dist/index.
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
16
|
"exports": {
|
|
17
|
-
".": "./dist/index.
|
|
17
|
+
".": "./dist/index.cjs"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"zerodot": {
|
|
24
24
|
"sdk": "^1.2",
|
|
25
|
-
"label": "Telegram"
|
|
25
|
+
"label": "Telegram",
|
|
26
|
+
"summary": "Send messages and react to bot updates"
|
|
26
27
|
},
|
|
27
28
|
"publishConfig": {
|
|
28
29
|
"access": "public"
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/node": "26.6.5",
|
|
37
|
-
"@zerodot/node-sdk": "^1.2.
|
|
38
|
+
"@zerodot/node-sdk": "^1.2.1",
|
|
38
39
|
"tsdown": "0.23.2",
|
|
39
40
|
"tsx": "4.23.15",
|
|
40
41
|
"typescript": "7.0.2",
|