@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,76 @@
|
|
|
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 { sendLocationActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramSendLocationAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'send_location',
|
|
10
|
+
displayName: 'Send Location',
|
|
11
|
+
description: 'Send a geographic location (latitude/longitude) to a Telegram chat',
|
|
12
|
+
audience: 'human',
|
|
13
|
+
aiMetadata: { description: 'Sends a point location given as latitude and longitude to a Telegram chat, optionally as a live location that updates for a set period. Use to share a place or track a moving position; both coordinates are required. Not idempotent: each call posts a new location message.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
18
|
+
latitude: Property.Number({
|
|
19
|
+
displayName: 'Latitude',
|
|
20
|
+
description: 'Latitude of the location.',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
longitude: Property.Number({
|
|
24
|
+
displayName: 'Longitude',
|
|
25
|
+
description: 'Longitude of the location.',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
horizontal_accuracy: Property.Number({
|
|
29
|
+
displayName: 'Horizontal Accuracy',
|
|
30
|
+
description: 'Radius of uncertainty for the location, in meters (0–1500).',
|
|
31
|
+
required: false,
|
|
32
|
+
}),
|
|
33
|
+
live_period: Property.Number({
|
|
34
|
+
displayName: 'Live Period',
|
|
35
|
+
description:
|
|
36
|
+
'Number of seconds the location will be updated (60–86400). Use for live locations.',
|
|
37
|
+
required: false,
|
|
38
|
+
}),
|
|
39
|
+
heading: Property.Number({
|
|
40
|
+
displayName: 'Heading',
|
|
41
|
+
description: 'For live locations, direction the user is moving in degrees (1–360).',
|
|
42
|
+
required: false,
|
|
43
|
+
}),
|
|
44
|
+
proximity_alert_radius: Property.Number({
|
|
45
|
+
displayName: 'Proximity Alert Radius',
|
|
46
|
+
description:
|
|
47
|
+
'For live locations, the max distance (1–100000 m) for proximity alerts about approaching another chat member.',
|
|
48
|
+
required: false,
|
|
49
|
+
}),
|
|
50
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
51
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
52
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
53
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
54
|
+
},
|
|
55
|
+
outputSchema: sendLocationActionOutputSchema,
|
|
56
|
+
async run(ctx) {
|
|
57
|
+
return await httpClient.sendRequest<never>({
|
|
58
|
+
method: HttpMethod.POST,
|
|
59
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendLocation'),
|
|
60
|
+
body: {
|
|
61
|
+
chat_id: ctx.propsValue.chat_id,
|
|
62
|
+
latitude: ctx.propsValue.latitude,
|
|
63
|
+
longitude: ctx.propsValue.longitude,
|
|
64
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
65
|
+
horizontal_accuracy: ctx.propsValue.horizontal_accuracy ?? undefined,
|
|
66
|
+
live_period: ctx.propsValue.live_period ?? undefined,
|
|
67
|
+
heading: ctx.propsValue.heading ?? undefined,
|
|
68
|
+
proximity_alert_radius: ctx.propsValue.proximity_alert_radius ?? undefined,
|
|
69
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
70
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
71
|
+
reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
|
|
72
|
+
reply_markup: ctx.propsValue.reply_markup ?? undefined,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { sendMediaGroupActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
const MEDIA_GROUP_LIMIT = 10;
|
|
8
|
+
|
|
9
|
+
type MediaItem = {
|
|
10
|
+
type: 'photo' | 'video' | 'audio' | 'document';
|
|
11
|
+
media: string;
|
|
12
|
+
caption?: string;
|
|
13
|
+
parse_mode?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const telegramSendMediaGroupAction = createAction({
|
|
17
|
+
auth: telegramBotAuth,
|
|
18
|
+
name: 'send_media_group',
|
|
19
|
+
displayName: 'Send Media Group',
|
|
20
|
+
description:
|
|
21
|
+
'Send a group of 2–10 photos, videos, documents or audios as an album to a chat',
|
|
22
|
+
audience: 'human',
|
|
23
|
+
aiMetadata: { description: 'Sends 2–10 media items (each a public URL or a Telegram file_id) as a single grouped album to a chat. Use to post several photos/videos together; photo and video may be mixed, but audio-only and document-only groups cannot be combined with other types. Not idempotent: each call posts a new album.', idempotent: false },
|
|
24
|
+
props: {
|
|
25
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
26
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
27
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
28
|
+
media: Property.Array({
|
|
29
|
+
displayName: 'Media',
|
|
30
|
+
description:
|
|
31
|
+
'Media items to send. Each must be a URL or a Telegram file_id. Mixing photo/video is allowed; audio and document groups cannot be mixed with other types.',
|
|
32
|
+
required: true,
|
|
33
|
+
properties: {
|
|
34
|
+
type: Property.StaticDropdown({
|
|
35
|
+
displayName: 'Type',
|
|
36
|
+
required: true,
|
|
37
|
+
options: {
|
|
38
|
+
options: [
|
|
39
|
+
{ label: 'Photo', value: 'photo' },
|
|
40
|
+
{ label: 'Video', value: 'video' },
|
|
41
|
+
{ label: 'Audio', value: 'audio' },
|
|
42
|
+
{ label: 'Document', value: 'document' },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
defaultValue: 'photo',
|
|
46
|
+
}),
|
|
47
|
+
media: Property.ShortText({
|
|
48
|
+
displayName: 'Media URL or File Id',
|
|
49
|
+
description:
|
|
50
|
+
'Public URL or a Telegram file_id of an already uploaded media item.',
|
|
51
|
+
required: true,
|
|
52
|
+
}),
|
|
53
|
+
caption: Property.LongText({
|
|
54
|
+
displayName: 'Caption',
|
|
55
|
+
required: false,
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
parse_mode: telegramCommons.parseModeProp(),
|
|
60
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
61
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
62
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
63
|
+
},
|
|
64
|
+
outputSchema: sendMediaGroupActionOutputSchema,
|
|
65
|
+
async run(ctx) {
|
|
66
|
+
const items = (ctx.propsValue.media ?? []) as Array<Record<string, unknown>>;
|
|
67
|
+
if (items.length < 2 || items.length > MEDIA_GROUP_LIMIT) {
|
|
68
|
+
throw new Error('A media group must contain 2–10 media items.');
|
|
69
|
+
}
|
|
70
|
+
const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.parse_mode);
|
|
71
|
+
|
|
72
|
+
const media: MediaItem[] = items.map((item) => {
|
|
73
|
+
const type = String(item['type'] ?? 'photo') as MediaItem['type'];
|
|
74
|
+
const value = String(item['media'] ?? '');
|
|
75
|
+
if (!value) {
|
|
76
|
+
throw new Error('Each media item must define a URL or file_id.');
|
|
77
|
+
}
|
|
78
|
+
const caption = item['caption'] ? String(item['caption']) : undefined;
|
|
79
|
+
const mediaItem: MediaItem = { type, media: value };
|
|
80
|
+
if (caption) mediaItem.caption = caption;
|
|
81
|
+
if (caption && parseMode) mediaItem.parse_mode = parseMode;
|
|
82
|
+
return mediaItem;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return await httpClient.sendRequest<never>({
|
|
86
|
+
method: HttpMethod.POST,
|
|
87
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendMediaGroup'),
|
|
88
|
+
body: {
|
|
89
|
+
chat_id: ctx.propsValue.chat_id,
|
|
90
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
91
|
+
media,
|
|
92
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
93
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
94
|
+
reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApFile,
|
|
3
|
+
createAction,
|
|
4
|
+
DynamicPropsValue,
|
|
5
|
+
Property,
|
|
6
|
+
} from '@agnocon/pieces-framework';
|
|
7
|
+
import {
|
|
8
|
+
HttpMessageBody,
|
|
9
|
+
HttpMethod,
|
|
10
|
+
QueryParams,
|
|
11
|
+
httpClient,
|
|
12
|
+
} from '@agnocon/pieces-common';
|
|
13
|
+
import { telegramCommons } from '../common';
|
|
14
|
+
import { telegramBotAuth } from '../..';
|
|
15
|
+
import FormData from 'form-data';
|
|
16
|
+
import { sendMediaActionOutputSchema } from '../output-schemas';
|
|
17
|
+
|
|
18
|
+
export const telegramSendMediaAction = createAction({
|
|
19
|
+
auth: telegramBotAuth,
|
|
20
|
+
name: 'send_media',
|
|
21
|
+
description: 'Send a media message (photo, video, sticker, GIF) through a Telegram bot',
|
|
22
|
+
audience: 'human',
|
|
23
|
+
aiMetadata: { description: 'Sends a single photo, video, sticker, or animated GIF to a Telegram chat, supplied either as an uploaded file or a previously uploaded Telegram file_id. Use when delivering one rich-media item with an optional caption; for multiple items in one album use Send Media Group. Not idempotent: each call posts a new message.', idempotent: false },
|
|
24
|
+
displayName: 'Send Media',
|
|
25
|
+
props: {
|
|
26
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
27
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
28
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
29
|
+
media_type: Property.StaticDropdown({
|
|
30
|
+
displayName: 'Media Type',
|
|
31
|
+
required: true,
|
|
32
|
+
options: {
|
|
33
|
+
disabled: false,
|
|
34
|
+
placeholder: 'Select media type',
|
|
35
|
+
options: [
|
|
36
|
+
{ label: 'Image', value: 'photo' },
|
|
37
|
+
{ label: 'Video', value: 'video' },
|
|
38
|
+
{ label: 'Sticker', value: 'sticker' },
|
|
39
|
+
{ label: 'GIF', value: 'animation' },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
media: Property.DynamicProperties({
|
|
44
|
+
auth: telegramBotAuth,
|
|
45
|
+
displayName: 'Media Properties',
|
|
46
|
+
required: false,
|
|
47
|
+
refreshers: ['media_type'],
|
|
48
|
+
async props({ media_type }) {
|
|
49
|
+
const propsBuilders: Record<string, () => DynamicPropsValue> = {
|
|
50
|
+
photo: () => ({
|
|
51
|
+
photo: Property.File({
|
|
52
|
+
displayName: 'Image',
|
|
53
|
+
description: 'The image to be uploaded as a file',
|
|
54
|
+
required: false,
|
|
55
|
+
}),
|
|
56
|
+
photoId: Property.ShortText({
|
|
57
|
+
displayName: 'Image Id',
|
|
58
|
+
description:
|
|
59
|
+
"The image id previously uploaded to Telegram's servers",
|
|
60
|
+
required: false,
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
video: () => ({
|
|
64
|
+
video: Property.File({
|
|
65
|
+
displayName: 'Video',
|
|
66
|
+
description: 'The video to be uploaded as a file',
|
|
67
|
+
required: false,
|
|
68
|
+
}),
|
|
69
|
+
videoId: Property.ShortText({
|
|
70
|
+
displayName: 'Video Id',
|
|
71
|
+
description:
|
|
72
|
+
"The video id previously uploaded to Telegram's servers",
|
|
73
|
+
required: false,
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
sticker: () => ({
|
|
77
|
+
sticker: Property.File({
|
|
78
|
+
displayName: 'Sticker',
|
|
79
|
+
description:
|
|
80
|
+
'The sticker to be uploaded as a file (supports .WEBP files for static and .TGS for animated)',
|
|
81
|
+
required: false,
|
|
82
|
+
}),
|
|
83
|
+
emoji: Property.ShortText({
|
|
84
|
+
displayName: 'Emoji',
|
|
85
|
+
description:
|
|
86
|
+
'Emoji associated with the sticker. Only for just uploaded stickers',
|
|
87
|
+
required: false,
|
|
88
|
+
}),
|
|
89
|
+
stickerId: Property.ShortText({
|
|
90
|
+
displayName: 'Sticker Id',
|
|
91
|
+
description:
|
|
92
|
+
"The sticker id previously uploaded to Telegram's servers",
|
|
93
|
+
required: false,
|
|
94
|
+
}),
|
|
95
|
+
}),
|
|
96
|
+
animation: () => ({
|
|
97
|
+
animation: Property.File({
|
|
98
|
+
displayName: 'GIF',
|
|
99
|
+
description:
|
|
100
|
+
'The GIF or MPEG-4 without sound file to be uploaded as a auto-playing animation',
|
|
101
|
+
required: false,
|
|
102
|
+
}),
|
|
103
|
+
animationId: Property.ShortText({
|
|
104
|
+
displayName: 'GIF Id',
|
|
105
|
+
description:
|
|
106
|
+
"The GIF or MPEG-4 without sound id previously uploaded to Telegram's servers",
|
|
107
|
+
required: false,
|
|
108
|
+
}),
|
|
109
|
+
duration: Property.Number({
|
|
110
|
+
displayName: 'Duration',
|
|
111
|
+
description: 'Duration of sent video in seconds',
|
|
112
|
+
required: false,
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
116
|
+
const builder = propsBuilders[media_type as unknown as string];
|
|
117
|
+
if (!builder) {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
return builder();
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
format: telegramCommons.parseModeProp(),
|
|
124
|
+
instructions_format: telegramCommons.formatLinkInstructions(),
|
|
125
|
+
message: Property.LongText({
|
|
126
|
+
displayName: 'Caption',
|
|
127
|
+
description: 'The caption to send with the media',
|
|
128
|
+
required: false,
|
|
129
|
+
}),
|
|
130
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
131
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
132
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
133
|
+
},
|
|
134
|
+
outputSchema: sendMediaActionOutputSchema,
|
|
135
|
+
async run(ctx) {
|
|
136
|
+
const mediaType = ctx.propsValue['media_type'];
|
|
137
|
+
if (!mediaType) {
|
|
138
|
+
throw new Error('media_type is required');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const methods: Partial<Record<string, string>> = {
|
|
142
|
+
photo: 'sendPhoto',
|
|
143
|
+
video: 'sendVideo',
|
|
144
|
+
sticker: 'sendSticker',
|
|
145
|
+
animation: 'sendAnimation',
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const method = methods[mediaType];
|
|
149
|
+
if (!method) {
|
|
150
|
+
throw new Error('Unknown media type method (' + mediaType + ')');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const headers: Record<string, string> = {};
|
|
154
|
+
const queryParams: QueryParams = {};
|
|
155
|
+
let body: HttpMessageBody | undefined = undefined;
|
|
156
|
+
|
|
157
|
+
const file = ctx.propsValue.media?.[mediaType] as ApFile | undefined;
|
|
158
|
+
const id = ctx.propsValue.media?.[mediaType + 'Id'] as string | undefined;
|
|
159
|
+
const parseMode = telegramCommons.resolveParseMode(ctx.propsValue['format']);
|
|
160
|
+
|
|
161
|
+
if (file && file.data && file.filename) {
|
|
162
|
+
const form = new FormData();
|
|
163
|
+
form.append(mediaType, file.data, file.filename);
|
|
164
|
+
form.append('chat_id', ctx.propsValue['chat_id']);
|
|
165
|
+
if (ctx.propsValue['message']) {
|
|
166
|
+
form.append('caption', ctx.propsValue['message']);
|
|
167
|
+
}
|
|
168
|
+
if (ctx.propsValue['message_thread_id']) {
|
|
169
|
+
form.append('message_thread_id', ctx.propsValue['message_thread_id']);
|
|
170
|
+
}
|
|
171
|
+
if (parseMode) {
|
|
172
|
+
form.append('parse_mode', parseMode);
|
|
173
|
+
}
|
|
174
|
+
if (ctx.propsValue['disable_notification']) {
|
|
175
|
+
form.append('disable_notification', 'true');
|
|
176
|
+
}
|
|
177
|
+
if (ctx.propsValue['protect_content']) {
|
|
178
|
+
form.append('protect_content', 'true');
|
|
179
|
+
}
|
|
180
|
+
if (ctx.propsValue['reply_markup']) {
|
|
181
|
+
form.append('reply_markup', JSON.stringify(ctx.propsValue['reply_markup']));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
body = form;
|
|
185
|
+
Object.assign(headers, form.getHeaders());
|
|
186
|
+
} else if (typeof id !== 'undefined' && id !== '') {
|
|
187
|
+
body = {
|
|
188
|
+
[mediaType]: id,
|
|
189
|
+
chat_id: ctx.propsValue['chat_id'],
|
|
190
|
+
caption: ctx.propsValue['message'] ?? undefined,
|
|
191
|
+
message_thread_id: ctx.propsValue['message_thread_id'] ?? undefined,
|
|
192
|
+
parse_mode: parseMode,
|
|
193
|
+
disable_notification: ctx.propsValue['disable_notification'] ?? false,
|
|
194
|
+
protect_content: ctx.propsValue['protect_content'] ?? false,
|
|
195
|
+
reply_markup: ctx.propsValue['reply_markup'] ?? undefined,
|
|
196
|
+
};
|
|
197
|
+
} else {
|
|
198
|
+
throw new Error('No media defined. Provide either a file or an id.');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return await httpClient.sendRequest<never>({
|
|
202
|
+
method: HttpMethod.POST,
|
|
203
|
+
url: telegramCommons.getApiUrl(ctx.auth, method),
|
|
204
|
+
headers,
|
|
205
|
+
body,
|
|
206
|
+
queryParams,
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { sendPollActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramSendPollAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'send_poll',
|
|
10
|
+
displayName: 'Send Poll',
|
|
11
|
+
description: 'Send a native Telegram poll (regular or quiz) to a chat',
|
|
12
|
+
audience: 'human',
|
|
13
|
+
aiMetadata: { description: 'Posts a native Telegram poll (regular or quiz) to a chat with 2–10 answer options. Use to collect votes or run a quiz; quiz polls require a correct_option_id and cannot allow multiple answers, and open_period and close_date are mutually exclusive. Not idempotent: each call creates a new poll.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
18
|
+
question: Property.ShortText({
|
|
19
|
+
displayName: 'Question',
|
|
20
|
+
description: 'Poll question, 1–300 characters.',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
options: Property.Array({
|
|
24
|
+
displayName: 'Options',
|
|
25
|
+
description: 'List of answer options (2–10 options, each 1–100 characters).',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
is_anonymous: Property.Checkbox({
|
|
29
|
+
displayName: 'Anonymous',
|
|
30
|
+
description: 'True, if the poll needs to be anonymous. Default true.',
|
|
31
|
+
required: false,
|
|
32
|
+
defaultValue: true,
|
|
33
|
+
}),
|
|
34
|
+
type: Property.StaticDropdown({
|
|
35
|
+
displayName: 'Poll Type',
|
|
36
|
+
description: 'Poll type. Defaults to "regular".',
|
|
37
|
+
required: false,
|
|
38
|
+
options: {
|
|
39
|
+
options: [
|
|
40
|
+
{ label: 'Regular', value: 'regular' },
|
|
41
|
+
{ label: 'Quiz', value: 'quiz' },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
defaultValue: 'regular',
|
|
45
|
+
}),
|
|
46
|
+
allows_multiple_answers: Property.Checkbox({
|
|
47
|
+
displayName: 'Allow Multiple Answers',
|
|
48
|
+
description: 'True if the poll allows multiple answers (regular polls only).',
|
|
49
|
+
required: false,
|
|
50
|
+
defaultValue: false,
|
|
51
|
+
}),
|
|
52
|
+
correct_option_id: Property.Number({
|
|
53
|
+
displayName: 'Correct Option Id (Quiz)',
|
|
54
|
+
description: '0-based index of the correct answer option (required for quizzes).',
|
|
55
|
+
required: false,
|
|
56
|
+
}),
|
|
57
|
+
explanation: Property.LongText({
|
|
58
|
+
displayName: 'Explanation (Quiz)',
|
|
59
|
+
description: 'Explanation shown when a user picks an incorrect answer (0–200 chars).',
|
|
60
|
+
required: false,
|
|
61
|
+
}),
|
|
62
|
+
explanation_parse_mode: telegramCommons.parseModeProp(),
|
|
63
|
+
open_period: Property.Number({
|
|
64
|
+
displayName: 'Open Period (seconds)',
|
|
65
|
+
description: 'Amount of time in seconds the poll will be active (5–600).',
|
|
66
|
+
required: false,
|
|
67
|
+
}),
|
|
68
|
+
close_date: Property.DateTime({
|
|
69
|
+
displayName: 'Close Date',
|
|
70
|
+
description: 'Point in time when the poll will be automatically closed.',
|
|
71
|
+
required: false,
|
|
72
|
+
}),
|
|
73
|
+
is_closed: Property.Checkbox({
|
|
74
|
+
displayName: 'Closed',
|
|
75
|
+
description: 'Pass True if the poll should be immediately closed. Useful for previews.',
|
|
76
|
+
required: false,
|
|
77
|
+
defaultValue: false,
|
|
78
|
+
}),
|
|
79
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
80
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
81
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
82
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
83
|
+
},
|
|
84
|
+
outputSchema: sendPollActionOutputSchema,
|
|
85
|
+
async run(ctx) {
|
|
86
|
+
const options = (ctx.propsValue.options ?? []).map((option) => String(option));
|
|
87
|
+
if (options.length < 2 || options.length > 10) {
|
|
88
|
+
throw new Error('A poll requires between 2 and 10 options.');
|
|
89
|
+
}
|
|
90
|
+
const pollType = ctx.propsValue.type ?? 'regular';
|
|
91
|
+
const correctOptionId = ctx.propsValue.correct_option_id;
|
|
92
|
+
if (pollType === 'quiz') {
|
|
93
|
+
if (correctOptionId === undefined || correctOptionId === null) {
|
|
94
|
+
throw new Error('Quiz polls require "Correct Option Id".');
|
|
95
|
+
}
|
|
96
|
+
if (correctOptionId < 0 || correctOptionId >= options.length) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`"Correct Option Id" must be between 0 and ${options.length - 1} (the index of an option).`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (ctx.propsValue.allows_multiple_answers) {
|
|
102
|
+
throw new Error('Quiz polls cannot allow multiple answers.');
|
|
103
|
+
}
|
|
104
|
+
} else if (correctOptionId !== undefined && correctOptionId !== null) {
|
|
105
|
+
throw new Error('"Correct Option Id" is only valid for quiz polls. Set "Poll Type" to Quiz or clear this field.');
|
|
106
|
+
}
|
|
107
|
+
if (ctx.propsValue.open_period && ctx.propsValue.close_date) {
|
|
108
|
+
throw new Error('"Open Period" and "Close Date" are mutually exclusive — set at most one.');
|
|
109
|
+
}
|
|
110
|
+
const explanationParseMode = telegramCommons.resolveParseMode(
|
|
111
|
+
ctx.propsValue.explanation_parse_mode
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return await httpClient.sendRequest<never>({
|
|
115
|
+
method: HttpMethod.POST,
|
|
116
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendPoll'),
|
|
117
|
+
body: {
|
|
118
|
+
chat_id: ctx.propsValue.chat_id,
|
|
119
|
+
question: ctx.propsValue.question,
|
|
120
|
+
options,
|
|
121
|
+
message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
|
|
122
|
+
is_anonymous: ctx.propsValue.is_anonymous ?? true,
|
|
123
|
+
type: ctx.propsValue.type ?? 'regular',
|
|
124
|
+
allows_multiple_answers: ctx.propsValue.allows_multiple_answers ?? false,
|
|
125
|
+
correct_option_id: ctx.propsValue.correct_option_id ?? undefined,
|
|
126
|
+
explanation: ctx.propsValue.explanation ?? undefined,
|
|
127
|
+
explanation_parse_mode: explanationParseMode,
|
|
128
|
+
open_period: ctx.propsValue.open_period ?? undefined,
|
|
129
|
+
close_date: ctx.propsValue.close_date
|
|
130
|
+
? Math.floor(new Date(ctx.propsValue.close_date).getTime() / 1000)
|
|
131
|
+
: undefined,
|
|
132
|
+
is_closed: ctx.propsValue.is_closed ?? false,
|
|
133
|
+
disable_notification: ctx.propsValue.disable_notification ?? false,
|
|
134
|
+
protect_content: ctx.propsValue.protect_content ?? false,
|
|
135
|
+
reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
|
|
136
|
+
reply_markup: ctx.propsValue.reply_markup ?? undefined,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { sendTextMessageActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramSendMessageAction = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'send_text_message',
|
|
10
|
+
description: 'Send a text message through a Telegram bot',
|
|
11
|
+
audience: 'human',
|
|
12
|
+
aiMetadata: { description: 'Posts a text message to a Telegram chat, group, or channel via the bot, addressed by chat_id (numeric id or @channelusername the bot can reach). Use to deliver notifications, replies, or alerts; supports Markdown/HTML formatting and inline keyboards. Not idempotent: each call sends a new message.', idempotent: false },
|
|
13
|
+
displayName: 'Send Text Message',
|
|
14
|
+
props: {
|
|
15
|
+
instructions: telegramCommons.chatIdInstructions(),
|
|
16
|
+
chat_id: telegramCommons.chatIdProp(),
|
|
17
|
+
message_thread_id: telegramCommons.messageThreadIdProp(),
|
|
18
|
+
format: telegramCommons.parseModeProp(),
|
|
19
|
+
instructions_format: telegramCommons.formatLinkInstructions(),
|
|
20
|
+
web_page_preview: Property.Checkbox({
|
|
21
|
+
displayName: 'Disable Web Page Preview',
|
|
22
|
+
description: 'Disable link previews for links in this message.',
|
|
23
|
+
required: false,
|
|
24
|
+
defaultValue: false,
|
|
25
|
+
}),
|
|
26
|
+
disable_notification: telegramCommons.disableNotificationProp(),
|
|
27
|
+
protect_content: telegramCommons.protectContentProp(),
|
|
28
|
+
reply_to_message_id: telegramCommons.replyToMessageIdProp(),
|
|
29
|
+
message: Property.LongText({
|
|
30
|
+
displayName: 'Message',
|
|
31
|
+
description: 'The message to be sent',
|
|
32
|
+
required: true,
|
|
33
|
+
}),
|
|
34
|
+
reply_markup: telegramCommons.replyMarkupProp(),
|
|
35
|
+
},
|
|
36
|
+
outputSchema: sendTextMessageActionOutputSchema,
|
|
37
|
+
async run(ctx) {
|
|
38
|
+
return await httpClient.sendRequest<never>({
|
|
39
|
+
method: HttpMethod.POST,
|
|
40
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'sendMessage'),
|
|
41
|
+
body: {
|
|
42
|
+
chat_id: ctx.propsValue['chat_id'],
|
|
43
|
+
text: ctx.propsValue['message'],
|
|
44
|
+
message_thread_id: ctx.propsValue['message_thread_id'] ?? undefined,
|
|
45
|
+
parse_mode: telegramCommons.resolveParseMode(ctx.propsValue['format']),
|
|
46
|
+
reply_markup: ctx.propsValue['reply_markup'] ?? undefined,
|
|
47
|
+
disable_web_page_preview: ctx.propsValue['web_page_preview'] ?? false,
|
|
48
|
+
disable_notification: ctx.propsValue['disable_notification'] ?? false,
|
|
49
|
+
protect_content: ctx.propsValue['protect_content'] ?? false,
|
|
50
|
+
reply_to_message_id: ctx.propsValue['reply_to_message_id'] ?? undefined,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { telegramAnswerCallbackQueryActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const telegramAnswerCallbackQuery = createAction({
|
|
8
|
+
auth: telegramBotAuth,
|
|
9
|
+
name: 'telegram_answer_callback_query',
|
|
10
|
+
displayName: 'Answer Callback Query',
|
|
11
|
+
description: 'Respond to a callback query raised by an inline keyboard button tap.',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Acknowledges a callback query raised when a user taps an inline keyboard button, identified by callback_query_id (from the callback-query trigger payload), optionally showing a toast or alert. Use to stop the button spinner and give feedback; a given query can be answered only once. Not idempotent: it is a one-time response to that query.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: telegramAnswerCallbackQueryActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
callback_query_id: Property.ShortText({
|
|
21
|
+
displayName: 'Callback Query Id',
|
|
22
|
+
description:
|
|
23
|
+
'Unique identifier of the callback query. Available on callback_query.id in the New Callback Query trigger payload.',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
text: Property.LongText({
|
|
27
|
+
displayName: 'Text',
|
|
28
|
+
description:
|
|
29
|
+
'Text shown to the user. If not specified, nothing is shown (the spinner is just stopped).',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
show_alert: Property.Checkbox({
|
|
33
|
+
displayName: 'Show Alert',
|
|
34
|
+
description:
|
|
35
|
+
'If True, an alert dialog is shown instead of a notification at the top of the screen.',
|
|
36
|
+
required: false,
|
|
37
|
+
defaultValue: false,
|
|
38
|
+
}),
|
|
39
|
+
url: Property.ShortText({
|
|
40
|
+
displayName: 'URL',
|
|
41
|
+
description: 'URL that will be opened by the user.',
|
|
42
|
+
required: false,
|
|
43
|
+
}),
|
|
44
|
+
cache_time: Property.Number({
|
|
45
|
+
displayName: 'Cache Time (seconds)',
|
|
46
|
+
description:
|
|
47
|
+
'The maximum amount of time in seconds the result of the callback query may be cached client-side.',
|
|
48
|
+
required: false,
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
async run(ctx) {
|
|
52
|
+
return await httpClient.sendRequest<never>({
|
|
53
|
+
method: HttpMethod.POST,
|
|
54
|
+
url: telegramCommons.getApiUrl(ctx.auth, 'answerCallbackQuery'),
|
|
55
|
+
body: {
|
|
56
|
+
callback_query_id: ctx.propsValue.callback_query_id,
|
|
57
|
+
text: ctx.propsValue.text ?? undefined,
|
|
58
|
+
show_alert: ctx.propsValue.show_alert ?? false,
|
|
59
|
+
url: ctx.propsValue.url ?? undefined,
|
|
60
|
+
cache_time: ctx.propsValue.cache_time ?? undefined,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
});
|