@divyacon/piece-telegram-bot 0.0.0-stage → 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/LICENSE.MIT-AP +24 -0
- package/README.md +8 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/action/answer-callback-query.action.d.ts +8 -0
- package/dist/lib/action/answer-callback-query.action.d.ts.map +1 -0
- package/dist/lib/action/answer-callback-query.action.js +63 -0
- package/dist/lib/action/answer-callback-query.action.js.map +1 -0
- package/dist/lib/action/create-invite-link.d.ts +9 -0
- package/dist/lib/action/create-invite-link.d.ts.map +1 -0
- package/dist/lib/action/create-invite-link.js +66 -0
- package/dist/lib/action/create-invite-link.js.map +1 -0
- package/dist/lib/action/delete-message.action.d.ts +6 -0
- package/dist/lib/action/delete-message.action.d.ts.map +1 -0
- package/dist/lib/action/delete-message.action.js +42 -0
- package/dist/lib/action/delete-message.action.js.map +1 -0
- package/dist/lib/action/edit-message-text.action.d.ts +12 -0
- package/dist/lib/action/edit-message-text.action.d.ts.map +1 -0
- package/dist/lib/action/edit-message-text.action.js +76 -0
- package/dist/lib/action/edit-message-text.action.js.map +1 -0
- package/dist/lib/action/forward-message.action.d.ts +10 -0
- package/dist/lib/action/forward-message.action.d.ts.map +1 -0
- package/dist/lib/action/forward-message.action.js +59 -0
- package/dist/lib/action/forward-message.action.js.map +1 -0
- package/dist/lib/action/get-chat-member.d.ts +6 -0
- package/dist/lib/action/get-chat-member.d.ts.map +1 -0
- package/dist/lib/action/get-chat-member.js +49 -0
- package/dist/lib/action/get-chat-member.js.map +1 -0
- package/dist/lib/action/get-chat.action.d.ts +5 -0
- package/dist/lib/action/get-chat.action.d.ts.map +1 -0
- package/dist/lib/action/get-chat.action.js +42 -0
- package/dist/lib/action/get-chat.action.js.map +1 -0
- package/dist/lib/action/get-file.action.d.ts +5 -0
- package/dist/lib/action/get-file.action.d.ts.map +1 -0
- package/dist/lib/action/get-file.action.js +69 -0
- package/dist/lib/action/get-file.action.js.map +1 -0
- package/dist/lib/action/pin-message.action.d.ts +7 -0
- package/dist/lib/action/pin-message.action.d.ts.map +1 -0
- package/dist/lib/action/pin-message.action.js +50 -0
- package/dist/lib/action/pin-message.action.js.map +1 -0
- package/dist/lib/action/request-approval-message.d.ts +7 -0
- package/dist/lib/action/request-approval-message.d.ts.map +1 -0
- package/dist/lib/action/request-approval-message.js +84 -0
- package/dist/lib/action/request-approval-message.js.map +1 -0
- package/dist/lib/action/send-audio.action.d.ts +18 -0
- package/dist/lib/action/send-audio.action.d.ts.map +1 -0
- package/dist/lib/action/send-audio.action.js +128 -0
- package/dist/lib/action/send-audio.action.js.map +1 -0
- package/dist/lib/action/send-chat-action.action.d.ts +7 -0
- package/dist/lib/action/send-chat-action.action.d.ts.map +1 -0
- package/dist/lib/action/send-chat-action.action.js +61 -0
- package/dist/lib/action/send-chat-action.action.js.map +1 -0
- package/dist/lib/action/send-document.action.d.ts +15 -0
- package/dist/lib/action/send-document.action.d.ts.map +1 -0
- package/dist/lib/action/send-document.action.js +104 -0
- package/dist/lib/action/send-document.action.js.map +1 -0
- package/dist/lib/action/send-location.action.d.ts +16 -0
- package/dist/lib/action/send-location.action.d.ts.map +1 -0
- package/dist/lib/action/send-location.action.js +83 -0
- package/dist/lib/action/send-location.action.js.map +1 -0
- package/dist/lib/action/send-media-group.action.d.ts +11 -0
- package/dist/lib/action/send-media-group.action.d.ts.map +1 -0
- package/dist/lib/action/send-media-group.action.js +97 -0
- package/dist/lib/action/send-media-group.action.js.map +1 -0
- package/dist/lib/action/send-media.action.d.ts +14 -0
- package/dist/lib/action/send-media.action.d.ts.map +1 -0
- package/dist/lib/action/send-media.action.js +198 -0
- package/dist/lib/action/send-media.action.js.map +1 -0
- package/dist/lib/action/send-poll.action.d.ts +21 -0
- package/dist/lib/action/send-poll.action.d.ts.map +1 -0
- package/dist/lib/action/send-poll.action.js +145 -0
- package/dist/lib/action/send-poll.action.js.map +1 -0
- package/dist/lib/action/send-text-message.action.d.ts +14 -0
- package/dist/lib/action/send-text-message.action.d.ts.map +1 -0
- package/dist/lib/action/send-text-message.action.js +63 -0
- package/dist/lib/action/send-text-message.action.js.map +1 -0
- package/dist/lib/action/telegram-answer-callback-query.d.ts +8 -0
- package/dist/lib/action/telegram-answer-callback-query.d.ts.map +1 -0
- package/dist/lib/action/telegram-answer-callback-query.js +68 -0
- package/dist/lib/action/telegram-answer-callback-query.js.map +1 -0
- package/dist/lib/action/telegram-create-invite-link.d.ts +8 -0
- package/dist/lib/action/telegram-create-invite-link.d.ts.map +1 -0
- package/dist/lib/action/telegram-create-invite-link.js +68 -0
- package/dist/lib/action/telegram-create-invite-link.js.map +1 -0
- package/dist/lib/action/telegram-delete-message.d.ts +5 -0
- package/dist/lib/action/telegram-delete-message.d.ts.map +1 -0
- package/dist/lib/action/telegram-delete-message.js +44 -0
- package/dist/lib/action/telegram-delete-message.js.map +1 -0
- package/dist/lib/action/telegram-edit-message-text.d.ts +10 -0
- package/dist/lib/action/telegram-edit-message-text.d.ts.map +1 -0
- package/dist/lib/action/telegram-edit-message-text.js +93 -0
- package/dist/lib/action/telegram-edit-message-text.js.map +1 -0
- package/dist/lib/action/telegram-forward-message.d.ts +9 -0
- package/dist/lib/action/telegram-forward-message.d.ts.map +1 -0
- package/dist/lib/action/telegram-forward-message.js +61 -0
- package/dist/lib/action/telegram-forward-message.js.map +1 -0
- package/dist/lib/action/telegram-get-bot-info.d.ts +2 -0
- package/dist/lib/action/telegram-get-bot-info.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-bot-info.js +39 -0
- package/dist/lib/action/telegram-get-bot-info.js.map +1 -0
- package/dist/lib/action/telegram-get-chat-administrators.d.ts +4 -0
- package/dist/lib/action/telegram-get-chat-administrators.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-chat-administrators.js +44 -0
- package/dist/lib/action/telegram-get-chat-administrators.js.map +1 -0
- package/dist/lib/action/telegram-get-chat-member-count.d.ts +4 -0
- package/dist/lib/action/telegram-get-chat-member-count.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-chat-member-count.js +44 -0
- package/dist/lib/action/telegram-get-chat-member-count.js.map +1 -0
- package/dist/lib/action/telegram-get-chat-member.d.ts +5 -0
- package/dist/lib/action/telegram-get-chat-member.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-chat-member.js +51 -0
- package/dist/lib/action/telegram-get-chat-member.js.map +1 -0
- package/dist/lib/action/telegram-get-chat.d.ts +4 -0
- package/dist/lib/action/telegram-get-chat.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-chat.js +44 -0
- package/dist/lib/action/telegram-get-chat.js.map +1 -0
- package/dist/lib/action/telegram-get-file.d.ts +5 -0
- package/dist/lib/action/telegram-get-file.d.ts.map +1 -0
- package/dist/lib/action/telegram-get-file.js +72 -0
- package/dist/lib/action/telegram-get-file.js.map +1 -0
- package/dist/lib/action/telegram-pin-message.d.ts +6 -0
- package/dist/lib/action/telegram-pin-message.d.ts.map +1 -0
- package/dist/lib/action/telegram-pin-message.js +52 -0
- package/dist/lib/action/telegram-pin-message.js.map +1 -0
- package/dist/lib/action/telegram-send-audio.d.ts +16 -0
- package/dist/lib/action/telegram-send-audio.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-audio.js +149 -0
- package/dist/lib/action/telegram-send-audio.js.map +1 -0
- package/dist/lib/action/telegram-send-chat-action.d.ts +6 -0
- package/dist/lib/action/telegram-send-chat-action.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-chat-action.js +67 -0
- package/dist/lib/action/telegram-send-chat-action.js.map +1 -0
- package/dist/lib/action/telegram-send-document.d.ts +13 -0
- package/dist/lib/action/telegram-send-document.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-document.js +125 -0
- package/dist/lib/action/telegram-send-document.js.map +1 -0
- package/dist/lib/action/telegram-send-location.d.ts +15 -0
- package/dist/lib/action/telegram-send-location.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-location.js +93 -0
- package/dist/lib/action/telegram-send-location.js.map +1 -0
- package/dist/lib/action/telegram-send-media-group.d.ts +10 -0
- package/dist/lib/action/telegram-send-media-group.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-media-group.js +115 -0
- package/dist/lib/action/telegram-send-media-group.js.map +1 -0
- package/dist/lib/action/telegram-send-message.d.ts +12 -0
- package/dist/lib/action/telegram-send-message.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-message.js +84 -0
- package/dist/lib/action/telegram-send-message.js.map +1 -0
- package/dist/lib/action/telegram-send-photo-or-video.d.ts +12 -0
- package/dist/lib/action/telegram-send-photo-or-video.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-photo-or-video.js +219 -0
- package/dist/lib/action/telegram-send-photo-or-video.js.map +1 -0
- package/dist/lib/action/telegram-send-poll.d.ts +20 -0
- package/dist/lib/action/telegram-send-poll.d.ts.map +1 -0
- package/dist/lib/action/telegram-send-poll.js +167 -0
- package/dist/lib/action/telegram-send-poll.js.map +1 -0
- package/dist/lib/action/telegram-unpin-message.d.ts +5 -0
- package/dist/lib/action/telegram-unpin-message.d.ts.map +1 -0
- package/dist/lib/action/telegram-unpin-message.js +45 -0
- package/dist/lib/action/telegram-unpin-message.js.map +1 -0
- package/dist/lib/action/unpin-message.action.d.ts +6 -0
- package/dist/lib/action/unpin-message.action.d.ts.map +1 -0
- package/dist/lib/action/unpin-message.action.js +43 -0
- package/dist/lib/action/unpin-message.action.js.map +1 -0
- package/dist/lib/common/index.d.ts +25 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +104 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/output-schemas.d.ts +41 -0
- package/dist/lib/output-schemas.d.ts.map +1 -0
- package/dist/lib/output-schemas.js +1853 -0
- package/dist/lib/output-schemas.js.map +1 -0
- package/dist/lib/trigger/new-message.d.ts +15 -0
- package/dist/lib/trigger/new-message.d.ts.map +1 -0
- package/dist/lib/trigger/new-message.js +121 -0
- package/dist/lib/trigger/new-message.js.map +1 -0
- package/package.json +44 -3
- package/src/index.ts +119 -0
- package/src/lib/action/answer-callback-query.action.ts +58 -0
- package/src/lib/action/create-invite-link.ts +59 -0
- package/src/lib/action/delete-message.action.ts +34 -0
- package/src/lib/action/edit-message-text.action.ts +71 -0
- package/src/lib/action/forward-message.action.ts +50 -0
- package/src/lib/action/get-chat-member.ts +40 -0
- package/src/lib/action/get-chat.action.ts +33 -0
- package/src/lib/action/get-file.action.ts +79 -0
- package/src/lib/action/pin-message.action.ts +41 -0
- package/src/lib/action/request-approval-message.ts +85 -0
- package/src/lib/action/send-audio.action.ts +123 -0
- package/src/lib/action/send-chat-action.action.ts +53 -0
- package/src/lib/action/send-document.action.ts +105 -0
- package/src/lib/action/send-location.action.ts +76 -0
- package/src/lib/action/send-media-group.action.ts +98 -0
- package/src/lib/action/send-media.action.ts +209 -0
- package/src/lib/action/send-poll.action.ts +140 -0
- package/src/lib/action/send-text-message.action.ts +54 -0
- package/src/lib/action/telegram-answer-callback-query.ts +64 -0
- package/src/lib/action/telegram-create-invite-link.ts +62 -0
- package/src/lib/action/telegram-delete-message.ts +37 -0
- package/src/lib/action/telegram-edit-message-text.ts +92 -0
- package/src/lib/action/telegram-forward-message.ts +54 -0
- package/src/lib/action/telegram-get-bot-info.ts +31 -0
- package/src/lib/action/telegram-get-chat-administrators.ts +36 -0
- package/src/lib/action/telegram-get-chat-member-count.ts +36 -0
- package/src/lib/action/telegram-get-chat-member.ts +43 -0
- package/src/lib/action/telegram-get-chat.ts +36 -0
- package/src/lib/action/telegram-get-file.ts +83 -0
- package/src/lib/action/telegram-pin-message.ts +45 -0
- package/src/lib/action/telegram-send-audio.ts +157 -0
- package/src/lib/action/telegram-send-chat-action.ts +61 -0
- package/src/lib/action/telegram-send-document.ts +136 -0
- package/src/lib/action/telegram-send-location.ts +89 -0
- package/src/lib/action/telegram-send-media-group.ts +119 -0
- package/src/lib/action/telegram-send-message.ts +79 -0
- package/src/lib/action/telegram-send-photo-or-video.ts +238 -0
- package/src/lib/action/telegram-send-poll.ts +170 -0
- package/src/lib/action/telegram-unpin-message.ts +38 -0
- package/src/lib/action/unpin-message.action.ts +36 -0
- package/src/lib/common/index.ts +147 -0
- package/src/lib/output-schemas.ts +1909 -0
- package/src/lib/trigger/new-message.ts +127 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { forwardMessageActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramForwardMessageAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'forward_message',
|
|
10
|
+
displayName: 'Forward Message',
|
|
11
|
+
description: 'Forward a message from one chat to another',
|
|
12
|
+
audience: 'human',
|
|
13
|
+
aiMetadata: { description: 'Forwards an existing message from a source chat (from_chat_id) to a target chat (chat_id), preserving its original sender attribution. Use to relay content the bot can access between chats. Not idempotent: each call creates a new forwarded message in the target chat.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: Property.ShortText({
|
|
17
|
+
displayName: 'Target Chat Id',
|
|
18
|
+
description: 'Chat the message will be forwarded to.',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
from_chat_id: Property.ShortText({
|
|
22
|
+
displayName: 'From Chat Id',
|
|
23
|
+
description: 'Chat the original message came from.',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
message_id: Property.Number({
|
|
27
|
+
displayName: 'Message Id',
|
|
28
|
+
description: 'Identifier of the message to forward.',
|
|
29
|
+
required: true,
|
|
30
|
+
}),
|
|
31
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
32
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
33
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
34
|
+
},
|
|
35
|
+
outputSchema: forwardMessageActionOutputSchema,
|
|
36
|
+
async run(ctx) {
|
|
37
|
+
return await httpClient.sendRequest<never>({
|
|
38
|
+
method: HttpMethod.POST,
|
|
39
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'forwardMessage'),
|
|
40
|
+
body: {
|
|
41
|
+
chat_id: ctx.propsValue.chat_id,
|
|
42
|
+
from_chat_id: ctx.propsValue.from_chat_id,
|
|
43
|
+
message_id: ctx.propsValue.message_id,
|
|
44
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
45
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
46
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { httpClient, HttpError, HttpMethod } from '@agnocon/pieces-common';
|
|
2
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
3
|
+
import { telegramBotAuth } from '../..';
|
|
4
|
+
import { telegramCommons } from '../common';
|
|
5
|
+
import { getChatMemberActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramGetChatMemberAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'get_chat_member',
|
|
10
|
+
description: 'Get member info (or null) for the provided chat id and user id',
|
|
11
|
+
audience: 'human',
|
|
12
|
+
aiMetadata: { description: 'Looks up a specific user\'s membership in a chat by chat_id and user_id, returning their role and status (member, administrator, left, kicked, etc.). Use to check whether a user belongs to a chat or what permissions they hold before acting. Idempotent: read-only lookup with no side effects.', idempotent: true },
|
|
13
|
+
displayName: 'Get Chat Member',
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
user_id: Property.ShortText({
|
|
18
|
+
displayName: 'User Id',
|
|
19
|
+
description: 'Unique identifier for the user',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
outputSchema: getChatMemberActionOutputSchema,
|
|
24
|
+
async run(ctx) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await httpClient.sendRequest<never>({
|
|
27
|
+
method: HttpMethod.POST,
|
|
28
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'getChatMember'),
|
|
29
|
+
headers: {},
|
|
30
|
+
body: {
|
|
31
|
+
chat_id: ctx.propsValue.chat_id,
|
|
32
|
+
user_id: ctx.propsValue.user_id,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return response.body;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return (error as HttpError).errorMessage().response.body;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HttpError, HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
2
|
+
import { createAction } from '@agnocon/pieces-framework';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { getChatActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramGetChatAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'get_chat',
|
|
10
|
+
displayName: 'Get Chat',
|
|
11
|
+
description: 'Get up-to-date information about a chat (name, description, photo, member count, etc.)',
|
|
12
|
+
audience: 'human',
|
|
13
|
+
aiMetadata: { description: 'Looks up current details about a chat (title, description, type, photo, member count, etc.) by chat_id. Use to resolve or inspect a chat before acting on it; the bot must be a member of or have access to the chat. Idempotent: read-only lookup with no side effects.', idempotent: true },
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
},
|
|
18
|
+
outputSchema: getChatActionOutputSchema,
|
|
19
|
+
async run(ctx) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await httpClient.sendRequest<never>({
|
|
22
|
+
method: HttpMethod.POST,
|
|
23
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'getChat'),
|
|
24
|
+
body: {
|
|
25
|
+
chat_id: ctx.propsValue.chat_id,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return response.body;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return (error as HttpError).errorMessage().response.body;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { getFileActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
type TelegramFileInfo = {
|
|
8
|
+
file_id: string;
|
|
9
|
+
file_unique_id: string;
|
|
10
|
+
file_size?: number;
|
|
11
|
+
file_path?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type TelegramGetFileResponse = {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
result: TelegramFileInfo;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const telegramGetFileAction = createAction({
|
|
20
|
+
auth: telegramBotAuth,
|
|
21
|
+
name: 'get_file',
|
|
22
|
+
description: 'Get file information and optionally download a file from Telegram',
|
|
23
|
+
audience: 'human',
|
|
24
|
+
aiMetadata: { description: 'Resolves a Telegram file_id to its file metadata and download URL, and optionally downloads the file content as base64 when download is enabled. Use to retrieve files attached to messages the bot received. Idempotent: read/download with no side effects, though Telegram download URLs are time-limited.', idempotent: true },
|
|
25
|
+
displayName: 'Get File',
|
|
26
|
+
props: {
|
|
27
|
+
file_id: Property.ShortText({
|
|
28
|
+
displayName: 'File ID',
|
|
29
|
+
description: 'File identifier to get information about',
|
|
30
|
+
required: true,
|
|
31
|
+
}),
|
|
32
|
+
download: Property.Checkbox({
|
|
33
|
+
displayName: 'Download File',
|
|
34
|
+
description: 'If enabled, the file is downloaded and returned as base64.',
|
|
35
|
+
required: false,
|
|
36
|
+
defaultValue: false,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
outputSchema: getFileActionOutputSchema,
|
|
40
|
+
async run(ctx) {
|
|
41
|
+
const fileInfoResponse = await httpClient.sendRequest<TelegramGetFileResponse>({
|
|
42
|
+
method: HttpMethod.POST,
|
|
43
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'getFile'),
|
|
44
|
+
body: {
|
|
45
|
+
file_id: ctx.propsValue.file_id,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!fileInfoResponse.body.ok) {
|
|
50
|
+
throw new Error(`Failed to get file info: ${JSON.stringify(fileInfoResponse.body)}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const fileInfo = fileInfoResponse.body.result;
|
|
54
|
+
const fileUrl = fileInfo.file_path
|
|
55
|
+
? `https://api.telegram.org/file/bot${ctx.auth.secret_text}/${fileInfo.file_path}`
|
|
56
|
+
: undefined;
|
|
57
|
+
|
|
58
|
+
if (ctx.propsValue.download && fileUrl) {
|
|
59
|
+
const fileResponse = await httpClient.sendRequest<Buffer>({
|
|
60
|
+
method: HttpMethod.GET,
|
|
61
|
+
url: fileUrl,
|
|
62
|
+
responseType: 'arraybuffer',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const base64Content = Buffer.from(fileResponse.body).toString('base64');
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
file_info: fileInfo,
|
|
69
|
+
file_url: fileUrl,
|
|
70
|
+
file_content_base64: base64Content,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
file_info: fileInfo,
|
|
76
|
+
file_url: fileUrl,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { pinMessageActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramPinMessageAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'pin_message',
|
|
10
|
+
displayName: 'Pin Message',
|
|
11
|
+
description: 'Pin a message in a chat. The bot must be an administrator in the chat for this to work.',
|
|
12
|
+
audience: 'human',
|
|
13
|
+
aiMetadata: { description: 'Pins an existing message in a chat, identified by chat_id and message_id; the bot must be an administrator with pin rights. Use to highlight an announcement or important message. Idempotent: pinning an already-pinned message leaves it pinned with the same result.', idempotent: true },
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
message_id: Property.Number({
|
|
18
|
+
displayName: 'Message Id',
|
|
19
|
+
description: 'Identifier of the message to pin.',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
disable_notification: Property.Checkbox({
|
|
23
|
+
displayName: 'Disable Notification',
|
|
24
|
+
description: 'Pass True if it is not necessary to send a notification to all chat members.',
|
|
25
|
+
required: false,
|
|
26
|
+
defaultValue: false,
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
outputSchema: pinMessageActionOutputSchema,
|
|
30
|
+
async run(ctx) {
|
|
31
|
+
return await httpClient.sendRequest<never>({
|
|
32
|
+
method: HttpMethod.POST,
|
|
33
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'pinChatMessage'),
|
|
34
|
+
body: {
|
|
35
|
+
chat_id: ctx.propsValue.chat_id,
|
|
36
|
+
message_id: ctx.propsValue.message_id,
|
|
37
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { assertNotNullOrUndefined } from '@agnocon/pieces-framework';
|
|
6
|
+
import { ExecutionType } from '@agnocon/pieces-framework';
|
|
7
|
+
import { requestApprovalMessageActionOutputSchema } from '../output-schemas';
|
|
8
|
+
|
|
9
|
+
export const telegramRequestApprovalMessageAction = createAction({
|
|
10
|
+
auth: telegramBotAuth,
|
|
11
|
+
name: 'request_approval_message',
|
|
12
|
+
displayName: 'Request Approval Message',
|
|
13
|
+
description:
|
|
14
|
+
'Send an approval message to a chat and wait until the message is approved or disapproved',
|
|
15
|
+
audience: 'both',
|
|
16
|
+
aiMetadata: { description: 'Sends a message with a single button linking to a confirmation page where the recipient chooses Approve or Disapprove, then pauses the flow until they respond and resumes with the decision. Use as a human approval gate before a sensitive downstream step. Not idempotent: each call sends a new message and opens a new pause/wait.', idempotent: false },
|
|
17
|
+
props: {
|
|
18
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
19
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
20
|
+
message: Property.LongText({
|
|
21
|
+
displayName: 'Message',
|
|
22
|
+
description: 'The approval message to be sent',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
parse_mode: telegramCommons.parseModeProp(),
|
|
26
|
+
},
|
|
27
|
+
outputSchema: requestApprovalMessageActionOutputSchema,
|
|
28
|
+
async run(context) {
|
|
29
|
+
if (context.executionType === ExecutionType.BEGIN) {
|
|
30
|
+
const token = context.auth.secret_text;
|
|
31
|
+
const { chat_id, message, parse_mode } = context.propsValue;
|
|
32
|
+
|
|
33
|
+
assertNotNullOrUndefined(token, 'token');
|
|
34
|
+
assertNotNullOrUndefined(message, 'message');
|
|
35
|
+
assertNotNullOrUndefined(chat_id, 'chat_id');
|
|
36
|
+
|
|
37
|
+
// Generate approval and disapproval links
|
|
38
|
+
const waitpoint = await context.run.createWaitpoint({
|
|
39
|
+
type: 'WEBHOOK',
|
|
40
|
+
});
|
|
41
|
+
const confirmationLink = `${waitpoint.resumeUrl}/confirm?chat_id=${encodeURIComponent(chat_id)}`;
|
|
42
|
+
|
|
43
|
+
// Send message with a single button opening the confirmation page (the recipient
|
|
44
|
+
// chooses Approve/Disapprove there). A single link keeps the message-preview
|
|
45
|
+
// prefetch from consuming the waitpoint.
|
|
46
|
+
const response = await httpClient.sendRequest<{
|
|
47
|
+
ok: boolean;
|
|
48
|
+
result: { message_id: number };
|
|
49
|
+
}>({
|
|
50
|
+
method: HttpMethod.POST,
|
|
51
|
+
url: telegramCommons.getApiUrl(context.auth, 'sendMessage'),
|
|
52
|
+
body: {
|
|
53
|
+
chat_id,
|
|
54
|
+
text: message,
|
|
55
|
+
parse_mode: telegramCommons.resolveParseMode(parse_mode),
|
|
56
|
+
reply_markup: {
|
|
57
|
+
inline_keyboard: [
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
text: 'Review & Respond',
|
|
61
|
+
url: confirmationLink,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const messageId = response.body.result.message_id;
|
|
70
|
+
|
|
71
|
+
context.run.waitForWaitpoint(waitpoint.id);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
approved: false, // default approval is false
|
|
75
|
+
messageId,
|
|
76
|
+
chatId: chat_id,
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
return {
|
|
80
|
+
approved: context.resumePayload.queryParams['action'] === 'approve',
|
|
81
|
+
chatId: context.resumePayload.queryParams['chat_id'],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApFile,
|
|
3
|
+
createAction,
|
|
4
|
+
Property,
|
|
5
|
+
} from '@agnocon/pieces-framework';
|
|
6
|
+
import {
|
|
7
|
+
HttpMessageBody,
|
|
8
|
+
HttpMethod,
|
|
9
|
+
httpClient,
|
|
10
|
+
} from '@agnocon/pieces-common';
|
|
11
|
+
import FormData from 'form-data';
|
|
12
|
+
import { telegramCommons } from '../common';
|
|
13
|
+
import { telegramBotAuth } from '../..';
|
|
14
|
+
import { sendAudioActionOutputSchema } from '../output-schemas';
|
|
15
|
+
|
|
16
|
+
export const telegramSendAudioAction = createAction({
|
|
17
|
+
auth: telegramBotAuth,
|
|
18
|
+
name: 'send_audio',
|
|
19
|
+
displayName: 'Send Audio',
|
|
20
|
+
description: 'Send an audio file to a Telegram chat (.MP3/.M4A — shown in the music player)',
|
|
21
|
+
audience: 'human',
|
|
22
|
+
aiMetadata: { description: 'Sends an audio file (.MP3/.M4A) to a Telegram chat where it appears in the music player, supplied as a file or a previously uploaded file_id, with optional performer and track title. Use for music or audio tracks; for raw file attachments use Send Document. Not idempotent: each call sends a new message.', idempotent: false },
|
|
23
|
+
props: {
|
|
24
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
25
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
26
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
27
|
+
audio: Property.File({
|
|
28
|
+
displayName: 'Audio',
|
|
29
|
+
description: 'The audio file to send (.MP3 or .M4A).',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
audio_id: Property.ShortText({
|
|
33
|
+
displayName: 'Audio Id',
|
|
34
|
+
description: 'Reuse an audio file previously uploaded to Telegram by passing its file_id.',
|
|
35
|
+
required: false,
|
|
36
|
+
}),
|
|
37
|
+
caption: Property.LongText({
|
|
38
|
+
displayName: 'Caption',
|
|
39
|
+
description: 'Optional caption (0–1024 chars).',
|
|
40
|
+
required: false,
|
|
41
|
+
}),
|
|
42
|
+
format: telegramCommons.parseModeProp(),
|
|
43
|
+
instructions_format: telegramCommons.formatLinkInstructions(),
|
|
44
|
+
duration: Property.Number({
|
|
45
|
+
displayName: 'Duration',
|
|
46
|
+
description: 'Duration of the audio in seconds.',
|
|
47
|
+
required: false,
|
|
48
|
+
}),
|
|
49
|
+
performer: Property.ShortText({
|
|
50
|
+
displayName: 'Performer',
|
|
51
|
+
description: 'Performer / artist name.',
|
|
52
|
+
required: false,
|
|
53
|
+
}),
|
|
54
|
+
title: Property.ShortText({
|
|
55
|
+
displayName: 'Track Title',
|
|
56
|
+
description: 'Track title.',
|
|
57
|
+
required: false,
|
|
58
|
+
}),
|
|
59
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
60
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
61
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
62
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
63
|
+
},
|
|
64
|
+
outputSchema: sendAudioActionOutputSchema,
|
|
65
|
+
async run(ctx) {
|
|
66
|
+
const file = ctx.propsValue.audio as ApFile | undefined;
|
|
67
|
+
const audioId = ctx.propsValue.audio_id;
|
|
68
|
+
const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.format);
|
|
69
|
+
|
|
70
|
+
if (!file && !audioId) {
|
|
71
|
+
throw new Error('Either an audio file or an audio id must be provided.');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const headers: Record<string, string> = {};
|
|
75
|
+
let body: HttpMessageBody;
|
|
76
|
+
|
|
77
|
+
if (file && file.data && file.filename) {
|
|
78
|
+
const form = new FormData();
|
|
79
|
+
form.append('audio', file.data, file.filename);
|
|
80
|
+
form.append('chat_id', ctx.propsValue.chat_id);
|
|
81
|
+
if (ctx.propsValue.caption) form.append('caption', ctx.propsValue.caption);
|
|
82
|
+
if (ctx.propsValue.message_thread_id) {
|
|
83
|
+
form.append('message_thread_id', ctx.propsValue.message_thread_id);
|
|
84
|
+
}
|
|
85
|
+
if (parseMode) form.append('parse_mode', parseMode);
|
|
86
|
+
if (ctx.propsValue.duration) form.append('duration', String(ctx.propsValue.duration));
|
|
87
|
+
if (ctx.propsValue.performer) form.append('performer', ctx.propsValue.performer);
|
|
88
|
+
if (ctx.propsValue.title) form.append('title', ctx.propsValue.title);
|
|
89
|
+
if (ctx.propsValue.disable_notification) form.append('disable_notification', 'true');
|
|
90
|
+
if (ctx.propsValue.protect_content) form.append('protect_content', 'true');
|
|
91
|
+
if (ctx.propsValue.reply_to_message_id) {
|
|
92
|
+
form.append('reply_to_message_id', String(ctx.propsValue.reply_to_message_id));
|
|
93
|
+
}
|
|
94
|
+
if (ctx.propsValue.reply_markup) {
|
|
95
|
+
form.append('reply_markup', JSON.stringify(ctx.propsValue.reply_markup));
|
|
96
|
+
}
|
|
97
|
+
body = form;
|
|
98
|
+
Object.assign(headers, form.getHeaders());
|
|
99
|
+
} else {
|
|
100
|
+
body = {
|
|
101
|
+
chat_id: ctx.propsValue.chat_id,
|
|
102
|
+
audio: audioId,
|
|
103
|
+
caption: ctx.propsValue.caption ?? undefined,
|
|
104
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
105
|
+
parse_mode: parseMode,
|
|
106
|
+
duration: ctx.propsValue.duration ?? undefined,
|
|
107
|
+
performer: ctx.propsValue.performer ?? undefined,
|
|
108
|
+
title: ctx.propsValue.title ?? undefined,
|
|
109
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
110
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
111
|
+
reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
|
|
112
|
+
reply_markup: ctx.propsValue.reply_markup ?? undefined,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return await httpClient.sendRequest<never>({
|
|
117
|
+
method: HttpMethod.POST,
|
|
118
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendAudio'),
|
|
119
|
+
headers,
|
|
120
|
+
body,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { telegramCommons } from '../common';
|
|
4
|
+
import { telegramBotAuth } from '../..';
|
|
5
|
+
import { sendChatActionActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramSendChatActionAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'send_chat_action',
|
|
10
|
+
displayName: 'Send Chat Action',
|
|
11
|
+
description:
|
|
12
|
+
'Show a status (typing, uploading photo, recording voice, etc.) on behalf of the bot in a chat. The status is shown for up to 5 seconds.',
|
|
13
|
+
audience: 'human',
|
|
14
|
+
aiMetadata: { description: 'Broadcasts a transient activity status (such as typing or uploading photo) in a chat, shown for up to 5 seconds. Use just before a slower action to signal the bot is working; it sends no message and produces no persistent content. Not idempotent: each call re-broadcasts the status.', idempotent: false },
|
|
15
|
+
props: {
|
|
16
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
17
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
18
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
19
|
+
action: Property.StaticDropdown({
|
|
20
|
+
displayName: 'Action',
|
|
21
|
+
description: 'Type of action to broadcast.',
|
|
22
|
+
required: true,
|
|
23
|
+
options: {
|
|
24
|
+
options: [
|
|
25
|
+
{ label: 'Typing', value: 'typing' },
|
|
26
|
+
{ label: 'Upload Photo', value: 'upload_photo' },
|
|
27
|
+
{ label: 'Record Video', value: 'record_video' },
|
|
28
|
+
{ label: 'Upload Video', value: 'upload_video' },
|
|
29
|
+
{ label: 'Record Voice', value: 'record_voice' },
|
|
30
|
+
{ label: 'Upload Voice', value: 'upload_voice' },
|
|
31
|
+
{ label: 'Upload Document', value: 'upload_document' },
|
|
32
|
+
{ label: 'Choose Sticker', value: 'choose_sticker' },
|
|
33
|
+
{ label: 'Find Location', value: 'find_location' },
|
|
34
|
+
{ label: 'Record Video Note', value: 'record_video_note' },
|
|
35
|
+
{ label: 'Upload Video Note', value: 'upload_video_note' },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
defaultValue: 'typing',
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
outputSchema: sendChatActionActionOutputSchema,
|
|
42
|
+
async run(ctx) {
|
|
43
|
+
return await httpClient.sendRequest<never>({
|
|
44
|
+
method: HttpMethod.POST,
|
|
45
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendChatAction'),
|
|
46
|
+
body: {
|
|
47
|
+
chat_id: ctx.propsValue.chat_id,
|
|
48
|
+
action: ctx.propsValue.action,
|
|
49
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApFile,
|
|
3
|
+
createAction,
|
|
4
|
+
Property,
|
|
5
|
+
} from '@agnocon/pieces-framework';
|
|
6
|
+
import {
|
|
7
|
+
HttpMessageBody,
|
|
8
|
+
HttpMethod,
|
|
9
|
+
httpClient,
|
|
10
|
+
} from '@agnocon/pieces-common';
|
|
11
|
+
import FormData from 'form-data';
|
|
12
|
+
import { telegramCommons } from '../common';
|
|
13
|
+
import { telegramBotAuth } from '../..';
|
|
14
|
+
import { sendDocumentActionOutputSchema } from '../output-schemas';
|
|
15
|
+
|
|
16
|
+
export const telegramSendDocumentAction = createAction({
|
|
17
|
+
auth: telegramBotAuth,
|
|
18
|
+
name: 'send_document',
|
|
19
|
+
displayName: 'Send Document',
|
|
20
|
+
description: 'Send a generic file (document) to a Telegram chat',
|
|
21
|
+
audience: 'human',
|
|
22
|
+
aiMetadata: { description: 'Uploads and sends a generic file (up to 50 MB) as a document to a Telegram chat, supplied as a file or a previously uploaded Telegram file_id. Use for arbitrary attachments (PDFs, archives, spreadsheets) rather than media shown inline. Not idempotent: each call sends a new document.', idempotent: false },
|
|
23
|
+
props: {
|
|
24
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
25
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
26
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
27
|
+
document: Property.File({
|
|
28
|
+
displayName: 'Document',
|
|
29
|
+
description: 'The document file to send. Telegram supports any file up to 50 MB.',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
document_id: Property.ShortText({
|
|
33
|
+
displayName: 'Document Id',
|
|
34
|
+
description:
|
|
35
|
+
'Reuse a document previously uploaded to Telegram by passing its file_id. Either provide a document or a document id.',
|
|
36
|
+
required: false,
|
|
37
|
+
}),
|
|
38
|
+
caption: Property.LongText({
|
|
39
|
+
displayName: 'Caption',
|
|
40
|
+
description: 'Optional caption to display below the document (0–1024 chars).',
|
|
41
|
+
required: false,
|
|
42
|
+
}),
|
|
43
|
+
format: telegramCommons.parseModeProp(),
|
|
44
|
+
instructions_format: telegramCommons.formatLinkInstructions(),
|
|
45
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
46
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
47
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
48
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
49
|
+
},
|
|
50
|
+
outputSchema: sendDocumentActionOutputSchema,
|
|
51
|
+
async run(ctx) {
|
|
52
|
+
const file = ctx.propsValue.document as ApFile | undefined;
|
|
53
|
+
const documentId = ctx.propsValue.document_id;
|
|
54
|
+
const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.format);
|
|
55
|
+
|
|
56
|
+
if (!file && !documentId) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
'Either a document file or a document id must be provided.'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const headers: Record<string, string> = {};
|
|
63
|
+
let body: HttpMessageBody;
|
|
64
|
+
|
|
65
|
+
if (file && file.data && file.filename) {
|
|
66
|
+
const form = new FormData();
|
|
67
|
+
form.append('document', file.data, file.filename);
|
|
68
|
+
form.append('chat_id', ctx.propsValue.chat_id);
|
|
69
|
+
if (ctx.propsValue.caption) form.append('caption', ctx.propsValue.caption);
|
|
70
|
+
if (ctx.propsValue.message_thread_id) {
|
|
71
|
+
form.append('message_thread_id', ctx.propsValue.message_thread_id);
|
|
72
|
+
}
|
|
73
|
+
if (parseMode) form.append('parse_mode', parseMode);
|
|
74
|
+
if (ctx.propsValue.disable_notification) form.append('disable_notification', 'true');
|
|
75
|
+
if (ctx.propsValue.protect_content) form.append('protect_content', 'true');
|
|
76
|
+
if (ctx.propsValue.reply_to_message_id) {
|
|
77
|
+
form.append('reply_to_message_id', String(ctx.propsValue.reply_to_message_id));
|
|
78
|
+
}
|
|
79
|
+
if (ctx.propsValue.reply_markup) {
|
|
80
|
+
form.append('reply_markup', JSON.stringify(ctx.propsValue.reply_markup));
|
|
81
|
+
}
|
|
82
|
+
body = form;
|
|
83
|
+
Object.assign(headers, form.getHeaders());
|
|
84
|
+
} else {
|
|
85
|
+
body = {
|
|
86
|
+
chat_id: ctx.propsValue.chat_id,
|
|
87
|
+
document: documentId,
|
|
88
|
+
caption: ctx.propsValue.caption ?? undefined,
|
|
89
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
90
|
+
parse_mode: parseMode,
|
|
91
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
92
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
93
|
+
reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
|
|
94
|
+
reply_markup: ctx.propsValue.reply_markup ?? undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return await httpClient.sendRequest<never>({
|
|
99
|
+
method: HttpMethod.POST,
|
|
100
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendDocument'),
|
|
101
|
+
headers,
|
|
102
|
+
body,
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
});
|