@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.
Files changed (223) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/README.md +8 -2
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +122 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/action/answer-callback-query.action.d.ts +8 -0
  8. package/dist/lib/action/answer-callback-query.action.d.ts.map +1 -0
  9. package/dist/lib/action/answer-callback-query.action.js +63 -0
  10. package/dist/lib/action/answer-callback-query.action.js.map +1 -0
  11. package/dist/lib/action/create-invite-link.d.ts +9 -0
  12. package/dist/lib/action/create-invite-link.d.ts.map +1 -0
  13. package/dist/lib/action/create-invite-link.js +66 -0
  14. package/dist/lib/action/create-invite-link.js.map +1 -0
  15. package/dist/lib/action/delete-message.action.d.ts +6 -0
  16. package/dist/lib/action/delete-message.action.d.ts.map +1 -0
  17. package/dist/lib/action/delete-message.action.js +42 -0
  18. package/dist/lib/action/delete-message.action.js.map +1 -0
  19. package/dist/lib/action/edit-message-text.action.d.ts +12 -0
  20. package/dist/lib/action/edit-message-text.action.d.ts.map +1 -0
  21. package/dist/lib/action/edit-message-text.action.js +76 -0
  22. package/dist/lib/action/edit-message-text.action.js.map +1 -0
  23. package/dist/lib/action/forward-message.action.d.ts +10 -0
  24. package/dist/lib/action/forward-message.action.d.ts.map +1 -0
  25. package/dist/lib/action/forward-message.action.js +59 -0
  26. package/dist/lib/action/forward-message.action.js.map +1 -0
  27. package/dist/lib/action/get-chat-member.d.ts +6 -0
  28. package/dist/lib/action/get-chat-member.d.ts.map +1 -0
  29. package/dist/lib/action/get-chat-member.js +49 -0
  30. package/dist/lib/action/get-chat-member.js.map +1 -0
  31. package/dist/lib/action/get-chat.action.d.ts +5 -0
  32. package/dist/lib/action/get-chat.action.d.ts.map +1 -0
  33. package/dist/lib/action/get-chat.action.js +42 -0
  34. package/dist/lib/action/get-chat.action.js.map +1 -0
  35. package/dist/lib/action/get-file.action.d.ts +5 -0
  36. package/dist/lib/action/get-file.action.d.ts.map +1 -0
  37. package/dist/lib/action/get-file.action.js +69 -0
  38. package/dist/lib/action/get-file.action.js.map +1 -0
  39. package/dist/lib/action/pin-message.action.d.ts +7 -0
  40. package/dist/lib/action/pin-message.action.d.ts.map +1 -0
  41. package/dist/lib/action/pin-message.action.js +50 -0
  42. package/dist/lib/action/pin-message.action.js.map +1 -0
  43. package/dist/lib/action/request-approval-message.d.ts +7 -0
  44. package/dist/lib/action/request-approval-message.d.ts.map +1 -0
  45. package/dist/lib/action/request-approval-message.js +84 -0
  46. package/dist/lib/action/request-approval-message.js.map +1 -0
  47. package/dist/lib/action/send-audio.action.d.ts +18 -0
  48. package/dist/lib/action/send-audio.action.d.ts.map +1 -0
  49. package/dist/lib/action/send-audio.action.js +128 -0
  50. package/dist/lib/action/send-audio.action.js.map +1 -0
  51. package/dist/lib/action/send-chat-action.action.d.ts +7 -0
  52. package/dist/lib/action/send-chat-action.action.d.ts.map +1 -0
  53. package/dist/lib/action/send-chat-action.action.js +61 -0
  54. package/dist/lib/action/send-chat-action.action.js.map +1 -0
  55. package/dist/lib/action/send-document.action.d.ts +15 -0
  56. package/dist/lib/action/send-document.action.d.ts.map +1 -0
  57. package/dist/lib/action/send-document.action.js +104 -0
  58. package/dist/lib/action/send-document.action.js.map +1 -0
  59. package/dist/lib/action/send-location.action.d.ts +16 -0
  60. package/dist/lib/action/send-location.action.d.ts.map +1 -0
  61. package/dist/lib/action/send-location.action.js +83 -0
  62. package/dist/lib/action/send-location.action.js.map +1 -0
  63. package/dist/lib/action/send-media-group.action.d.ts +11 -0
  64. package/dist/lib/action/send-media-group.action.d.ts.map +1 -0
  65. package/dist/lib/action/send-media-group.action.js +97 -0
  66. package/dist/lib/action/send-media-group.action.js.map +1 -0
  67. package/dist/lib/action/send-media.action.d.ts +14 -0
  68. package/dist/lib/action/send-media.action.d.ts.map +1 -0
  69. package/dist/lib/action/send-media.action.js +198 -0
  70. package/dist/lib/action/send-media.action.js.map +1 -0
  71. package/dist/lib/action/send-poll.action.d.ts +21 -0
  72. package/dist/lib/action/send-poll.action.d.ts.map +1 -0
  73. package/dist/lib/action/send-poll.action.js +145 -0
  74. package/dist/lib/action/send-poll.action.js.map +1 -0
  75. package/dist/lib/action/send-text-message.action.d.ts +14 -0
  76. package/dist/lib/action/send-text-message.action.d.ts.map +1 -0
  77. package/dist/lib/action/send-text-message.action.js +63 -0
  78. package/dist/lib/action/send-text-message.action.js.map +1 -0
  79. package/dist/lib/action/telegram-answer-callback-query.d.ts +8 -0
  80. package/dist/lib/action/telegram-answer-callback-query.d.ts.map +1 -0
  81. package/dist/lib/action/telegram-answer-callback-query.js +68 -0
  82. package/dist/lib/action/telegram-answer-callback-query.js.map +1 -0
  83. package/dist/lib/action/telegram-create-invite-link.d.ts +8 -0
  84. package/dist/lib/action/telegram-create-invite-link.d.ts.map +1 -0
  85. package/dist/lib/action/telegram-create-invite-link.js +68 -0
  86. package/dist/lib/action/telegram-create-invite-link.js.map +1 -0
  87. package/dist/lib/action/telegram-delete-message.d.ts +5 -0
  88. package/dist/lib/action/telegram-delete-message.d.ts.map +1 -0
  89. package/dist/lib/action/telegram-delete-message.js +44 -0
  90. package/dist/lib/action/telegram-delete-message.js.map +1 -0
  91. package/dist/lib/action/telegram-edit-message-text.d.ts +10 -0
  92. package/dist/lib/action/telegram-edit-message-text.d.ts.map +1 -0
  93. package/dist/lib/action/telegram-edit-message-text.js +93 -0
  94. package/dist/lib/action/telegram-edit-message-text.js.map +1 -0
  95. package/dist/lib/action/telegram-forward-message.d.ts +9 -0
  96. package/dist/lib/action/telegram-forward-message.d.ts.map +1 -0
  97. package/dist/lib/action/telegram-forward-message.js +61 -0
  98. package/dist/lib/action/telegram-forward-message.js.map +1 -0
  99. package/dist/lib/action/telegram-get-bot-info.d.ts +2 -0
  100. package/dist/lib/action/telegram-get-bot-info.d.ts.map +1 -0
  101. package/dist/lib/action/telegram-get-bot-info.js +39 -0
  102. package/dist/lib/action/telegram-get-bot-info.js.map +1 -0
  103. package/dist/lib/action/telegram-get-chat-administrators.d.ts +4 -0
  104. package/dist/lib/action/telegram-get-chat-administrators.d.ts.map +1 -0
  105. package/dist/lib/action/telegram-get-chat-administrators.js +44 -0
  106. package/dist/lib/action/telegram-get-chat-administrators.js.map +1 -0
  107. package/dist/lib/action/telegram-get-chat-member-count.d.ts +4 -0
  108. package/dist/lib/action/telegram-get-chat-member-count.d.ts.map +1 -0
  109. package/dist/lib/action/telegram-get-chat-member-count.js +44 -0
  110. package/dist/lib/action/telegram-get-chat-member-count.js.map +1 -0
  111. package/dist/lib/action/telegram-get-chat-member.d.ts +5 -0
  112. package/dist/lib/action/telegram-get-chat-member.d.ts.map +1 -0
  113. package/dist/lib/action/telegram-get-chat-member.js +51 -0
  114. package/dist/lib/action/telegram-get-chat-member.js.map +1 -0
  115. package/dist/lib/action/telegram-get-chat.d.ts +4 -0
  116. package/dist/lib/action/telegram-get-chat.d.ts.map +1 -0
  117. package/dist/lib/action/telegram-get-chat.js +44 -0
  118. package/dist/lib/action/telegram-get-chat.js.map +1 -0
  119. package/dist/lib/action/telegram-get-file.d.ts +5 -0
  120. package/dist/lib/action/telegram-get-file.d.ts.map +1 -0
  121. package/dist/lib/action/telegram-get-file.js +72 -0
  122. package/dist/lib/action/telegram-get-file.js.map +1 -0
  123. package/dist/lib/action/telegram-pin-message.d.ts +6 -0
  124. package/dist/lib/action/telegram-pin-message.d.ts.map +1 -0
  125. package/dist/lib/action/telegram-pin-message.js +52 -0
  126. package/dist/lib/action/telegram-pin-message.js.map +1 -0
  127. package/dist/lib/action/telegram-send-audio.d.ts +16 -0
  128. package/dist/lib/action/telegram-send-audio.d.ts.map +1 -0
  129. package/dist/lib/action/telegram-send-audio.js +149 -0
  130. package/dist/lib/action/telegram-send-audio.js.map +1 -0
  131. package/dist/lib/action/telegram-send-chat-action.d.ts +6 -0
  132. package/dist/lib/action/telegram-send-chat-action.d.ts.map +1 -0
  133. package/dist/lib/action/telegram-send-chat-action.js +67 -0
  134. package/dist/lib/action/telegram-send-chat-action.js.map +1 -0
  135. package/dist/lib/action/telegram-send-document.d.ts +13 -0
  136. package/dist/lib/action/telegram-send-document.d.ts.map +1 -0
  137. package/dist/lib/action/telegram-send-document.js +125 -0
  138. package/dist/lib/action/telegram-send-document.js.map +1 -0
  139. package/dist/lib/action/telegram-send-location.d.ts +15 -0
  140. package/dist/lib/action/telegram-send-location.d.ts.map +1 -0
  141. package/dist/lib/action/telegram-send-location.js +93 -0
  142. package/dist/lib/action/telegram-send-location.js.map +1 -0
  143. package/dist/lib/action/telegram-send-media-group.d.ts +10 -0
  144. package/dist/lib/action/telegram-send-media-group.d.ts.map +1 -0
  145. package/dist/lib/action/telegram-send-media-group.js +115 -0
  146. package/dist/lib/action/telegram-send-media-group.js.map +1 -0
  147. package/dist/lib/action/telegram-send-message.d.ts +12 -0
  148. package/dist/lib/action/telegram-send-message.d.ts.map +1 -0
  149. package/dist/lib/action/telegram-send-message.js +84 -0
  150. package/dist/lib/action/telegram-send-message.js.map +1 -0
  151. package/dist/lib/action/telegram-send-photo-or-video.d.ts +12 -0
  152. package/dist/lib/action/telegram-send-photo-or-video.d.ts.map +1 -0
  153. package/dist/lib/action/telegram-send-photo-or-video.js +219 -0
  154. package/dist/lib/action/telegram-send-photo-or-video.js.map +1 -0
  155. package/dist/lib/action/telegram-send-poll.d.ts +20 -0
  156. package/dist/lib/action/telegram-send-poll.d.ts.map +1 -0
  157. package/dist/lib/action/telegram-send-poll.js +167 -0
  158. package/dist/lib/action/telegram-send-poll.js.map +1 -0
  159. package/dist/lib/action/telegram-unpin-message.d.ts +5 -0
  160. package/dist/lib/action/telegram-unpin-message.d.ts.map +1 -0
  161. package/dist/lib/action/telegram-unpin-message.js +45 -0
  162. package/dist/lib/action/telegram-unpin-message.js.map +1 -0
  163. package/dist/lib/action/unpin-message.action.d.ts +6 -0
  164. package/dist/lib/action/unpin-message.action.d.ts.map +1 -0
  165. package/dist/lib/action/unpin-message.action.js +43 -0
  166. package/dist/lib/action/unpin-message.action.js.map +1 -0
  167. package/dist/lib/common/index.d.ts +25 -0
  168. package/dist/lib/common/index.d.ts.map +1 -0
  169. package/dist/lib/common/index.js +104 -0
  170. package/dist/lib/common/index.js.map +1 -0
  171. package/dist/lib/output-schemas.d.ts +41 -0
  172. package/dist/lib/output-schemas.d.ts.map +1 -0
  173. package/dist/lib/output-schemas.js +1853 -0
  174. package/dist/lib/output-schemas.js.map +1 -0
  175. package/dist/lib/trigger/new-message.d.ts +15 -0
  176. package/dist/lib/trigger/new-message.d.ts.map +1 -0
  177. package/dist/lib/trigger/new-message.js +121 -0
  178. package/dist/lib/trigger/new-message.js.map +1 -0
  179. package/package.json +44 -3
  180. package/src/index.ts +119 -0
  181. package/src/lib/action/answer-callback-query.action.ts +58 -0
  182. package/src/lib/action/create-invite-link.ts +59 -0
  183. package/src/lib/action/delete-message.action.ts +34 -0
  184. package/src/lib/action/edit-message-text.action.ts +71 -0
  185. package/src/lib/action/forward-message.action.ts +50 -0
  186. package/src/lib/action/get-chat-member.ts +40 -0
  187. package/src/lib/action/get-chat.action.ts +33 -0
  188. package/src/lib/action/get-file.action.ts +79 -0
  189. package/src/lib/action/pin-message.action.ts +41 -0
  190. package/src/lib/action/request-approval-message.ts +85 -0
  191. package/src/lib/action/send-audio.action.ts +123 -0
  192. package/src/lib/action/send-chat-action.action.ts +53 -0
  193. package/src/lib/action/send-document.action.ts +105 -0
  194. package/src/lib/action/send-location.action.ts +76 -0
  195. package/src/lib/action/send-media-group.action.ts +98 -0
  196. package/src/lib/action/send-media.action.ts +209 -0
  197. package/src/lib/action/send-poll.action.ts +140 -0
  198. package/src/lib/action/send-text-message.action.ts +54 -0
  199. package/src/lib/action/telegram-answer-callback-query.ts +64 -0
  200. package/src/lib/action/telegram-create-invite-link.ts +62 -0
  201. package/src/lib/action/telegram-delete-message.ts +37 -0
  202. package/src/lib/action/telegram-edit-message-text.ts +92 -0
  203. package/src/lib/action/telegram-forward-message.ts +54 -0
  204. package/src/lib/action/telegram-get-bot-info.ts +31 -0
  205. package/src/lib/action/telegram-get-chat-administrators.ts +36 -0
  206. package/src/lib/action/telegram-get-chat-member-count.ts +36 -0
  207. package/src/lib/action/telegram-get-chat-member.ts +43 -0
  208. package/src/lib/action/telegram-get-chat.ts +36 -0
  209. package/src/lib/action/telegram-get-file.ts +83 -0
  210. package/src/lib/action/telegram-pin-message.ts +45 -0
  211. package/src/lib/action/telegram-send-audio.ts +157 -0
  212. package/src/lib/action/telegram-send-chat-action.ts +61 -0
  213. package/src/lib/action/telegram-send-document.ts +136 -0
  214. package/src/lib/action/telegram-send-location.ts +89 -0
  215. package/src/lib/action/telegram-send-media-group.ts +119 -0
  216. package/src/lib/action/telegram-send-message.ts +79 -0
  217. package/src/lib/action/telegram-send-photo-or-video.ts +238 -0
  218. package/src/lib/action/telegram-send-poll.ts +170 -0
  219. package/src/lib/action/telegram-unpin-message.ts +38 -0
  220. package/src/lib/action/unpin-message.action.ts +36 -0
  221. package/src/lib/common/index.ts +147 -0
  222. package/src/lib/output-schemas.ts +1909 -0
  223. package/src/lib/trigger/new-message.ts +127 -0
@@ -0,0 +1,157 @@
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 { telegramSendAudioActionOutputSchema } from '../output-schemas';
15
+
16
+ export const telegramSendAudio = createAction({
17
+ auth: telegramBotAuth,
18
+ name: 'telegram_send_audio',
19
+ displayName: 'Send Audio',
20
+ description:
21
+ 'Send an audio file to a Telegram chat (.MP3/.M4A — shown in the music player).',
22
+ audience: 'ai',
23
+ aiMetadata: {
24
+ description:
25
+ 'Sends an audio file (.MP3/.M4A) that appears in the chat\'s music player (chat_id is a numeric id or @channelusername the bot can reach), supplied as an uploaded file OR a previously uploaded file_id, with optional performer and track title. Provide exactly one of audio or audio_id. Use for music or audio tracks; for a raw file attachment use telegram_send_document. Caption format defaults to plain text. Not idempotent: each call sends a new message.',
26
+ idempotent: false,
27
+ },
28
+ outputSchema: telegramSendAudioActionOutputSchema,
29
+ props: {
30
+ chat_id: telegramCommons.chatIdProp(),
31
+ audio: Property.File({
32
+ displayName: 'Audio',
33
+ description: 'The audio file to send (.MP3 or .M4A). Provide this or an audio_id.',
34
+ required: false,
35
+ }),
36
+ audio_id: Property.ShortText({
37
+ displayName: 'Audio Id',
38
+ description:
39
+ 'Reuse an audio file previously uploaded to Telegram by passing its file_id. Provide this or an audio file.',
40
+ required: false,
41
+ }),
42
+ caption: Property.LongText({
43
+ displayName: 'Caption',
44
+ description: 'Optional caption (0–1024 chars).',
45
+ required: false,
46
+ }),
47
+ format: Property.StaticDropdown({
48
+ displayName: 'Caption Format',
49
+ description:
50
+ 'How the caption should be parsed by Telegram. Defaults to plain text; only set MarkdownV2 or HTML when the caption is correctly escaped/tagged.',
51
+ required: false,
52
+ options: {
53
+ options: [
54
+ { label: 'Plain Text', value: 'None' },
55
+ { label: 'Markdown (V2)', value: 'MarkdownV2' },
56
+ { label: 'HTML', value: 'HTML' },
57
+ ],
58
+ },
59
+ defaultValue: 'None',
60
+ }),
61
+ duration: Property.Number({
62
+ displayName: 'Duration',
63
+ description: 'Duration of the audio in seconds.',
64
+ required: false,
65
+ }),
66
+ performer: Property.ShortText({
67
+ displayName: 'Performer',
68
+ description: 'Performer / artist name.',
69
+ required: false,
70
+ }),
71
+ title: Property.ShortText({
72
+ displayName: 'Track Title',
73
+ description: 'Track title.',
74
+ required: false,
75
+ }),
76
+ message_thread_id: Property.ShortText({
77
+ displayName: 'Message Thread Id',
78
+ description:
79
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
80
+ required: false,
81
+ }),
82
+ disable_notification: telegramCommons.disableNotificationProp(),
83
+ protect_content: telegramCommons.protectContentProp(),
84
+ reply_to_message_id: telegramCommons.replyToMessageIdProp(),
85
+ reply_markup: Property.Json({
86
+ displayName: 'Reply Markup',
87
+ description:
88
+ 'Advanced/optional. A raw JSON-serialized inline keyboard, e.g. {"inline_keyboard":[[{"text":"Open","url":"https://example.com"}]]}. Malformed markup is rejected by Telegram.',
89
+ required: false,
90
+ }),
91
+ },
92
+ async run(ctx) {
93
+ const file = ctx.propsValue.audio as ApFile | undefined;
94
+ const audioId = ctx.propsValue.audio_id;
95
+ const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.format);
96
+
97
+ if (!file && !audioId) {
98
+ throw new Error('Either an audio file or an audio id must be provided.');
99
+ }
100
+
101
+ const headers: Record<string, string> = {};
102
+ let body: HttpMessageBody;
103
+
104
+ if (file && file.data && file.filename) {
105
+ const form = new FormData();
106
+ form.append('audio', file.data, file.filename);
107
+ form.append('chat_id', ctx.propsValue.chat_id);
108
+ if (ctx.propsValue.caption) form.append('caption', ctx.propsValue.caption);
109
+ if (ctx.propsValue.message_thread_id) {
110
+ form.append('message_thread_id', ctx.propsValue.message_thread_id);
111
+ }
112
+ if (parseMode) form.append('parse_mode', parseMode);
113
+ if (ctx.propsValue.duration)
114
+ form.append('duration', String(ctx.propsValue.duration));
115
+ if (ctx.propsValue.performer)
116
+ form.append('performer', ctx.propsValue.performer);
117
+ if (ctx.propsValue.title) form.append('title', ctx.propsValue.title);
118
+ if (ctx.propsValue.disable_notification)
119
+ form.append('disable_notification', 'true');
120
+ if (ctx.propsValue.protect_content)
121
+ form.append('protect_content', 'true');
122
+ if (ctx.propsValue.reply_to_message_id) {
123
+ form.append(
124
+ 'reply_to_message_id',
125
+ String(ctx.propsValue.reply_to_message_id)
126
+ );
127
+ }
128
+ if (ctx.propsValue.reply_markup) {
129
+ form.append('reply_markup', JSON.stringify(ctx.propsValue.reply_markup));
130
+ }
131
+ body = form;
132
+ Object.assign(headers, form.getHeaders());
133
+ } else {
134
+ body = {
135
+ chat_id: ctx.propsValue.chat_id,
136
+ audio: audioId,
137
+ caption: ctx.propsValue.caption ?? undefined,
138
+ message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
139
+ parse_mode: parseMode,
140
+ duration: ctx.propsValue.duration ?? undefined,
141
+ performer: ctx.propsValue.performer ?? undefined,
142
+ title: ctx.propsValue.title ?? undefined,
143
+ disable_notification: ctx.propsValue.disable_notification ?? false,
144
+ protect_content: ctx.propsValue.protect_content ?? false,
145
+ reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
146
+ reply_markup: ctx.propsValue.reply_markup ?? undefined,
147
+ };
148
+ }
149
+
150
+ return await httpClient.sendRequest<never>({
151
+ method: HttpMethod.POST,
152
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendAudio'),
153
+ headers,
154
+ body,
155
+ });
156
+ },
157
+ });
@@ -0,0 +1,61 @@
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 { telegramSendChatActionActionOutputSchema } from '../output-schemas';
6
+
7
+ export const telegramSendChatAction = createAction({
8
+ auth: telegramBotAuth,
9
+ name: 'telegram_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: 'ai',
14
+ aiMetadata: {
15
+ description:
16
+ 'Broadcasts a transient activity status (such as typing or uploading photo) in a chat addressed by chat_id (a numeric id or @channelusername the bot can reach), 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.',
17
+ idempotent: false,
18
+ },
19
+ outputSchema: telegramSendChatActionActionOutputSchema,
20
+ props: {
21
+ chat_id: telegramCommons.chatIdProp(),
22
+ action: Property.StaticDropdown({
23
+ displayName: 'Action',
24
+ description: 'Type of action to broadcast.',
25
+ required: true,
26
+ options: {
27
+ options: [
28
+ { label: 'Typing', value: 'typing' },
29
+ { label: 'Upload Photo', value: 'upload_photo' },
30
+ { label: 'Record Video', value: 'record_video' },
31
+ { label: 'Upload Video', value: 'upload_video' },
32
+ { label: 'Record Voice', value: 'record_voice' },
33
+ { label: 'Upload Voice', value: 'upload_voice' },
34
+ { label: 'Upload Document', value: 'upload_document' },
35
+ { label: 'Choose Sticker', value: 'choose_sticker' },
36
+ { label: 'Find Location', value: 'find_location' },
37
+ { label: 'Record Video Note', value: 'record_video_note' },
38
+ { label: 'Upload Video Note', value: 'upload_video_note' },
39
+ ],
40
+ },
41
+ defaultValue: 'typing',
42
+ }),
43
+ message_thread_id: Property.ShortText({
44
+ displayName: 'Message Thread Id',
45
+ description:
46
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
47
+ required: false,
48
+ }),
49
+ },
50
+ async run(ctx) {
51
+ return await httpClient.sendRequest<never>({
52
+ method: HttpMethod.POST,
53
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendChatAction'),
54
+ body: {
55
+ chat_id: ctx.propsValue.chat_id,
56
+ action: ctx.propsValue.action,
57
+ message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
58
+ },
59
+ });
60
+ },
61
+ });
@@ -0,0 +1,136 @@
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 { telegramSendDocumentActionOutputSchema } from '../output-schemas';
15
+
16
+ export const telegramSendDocument = createAction({
17
+ auth: telegramBotAuth,
18
+ name: 'telegram_send_document',
19
+ displayName: 'Send Document',
20
+ description: 'Send a generic file (document) to a Telegram chat.',
21
+ audience: 'ai',
22
+ aiMetadata: {
23
+ description:
24
+ 'Uploads and sends a generic file (up to 50 MB) as a document to a chat (chat_id is a numeric id or @channelusername the bot can reach), supplied as an uploaded file OR a previously uploaded file_id. Provide exactly one of document or document_id. Use for arbitrary attachments (PDF, archive, spreadsheet); for media shown inline use telegram_send_photo_or_video, for music use telegram_send_audio. Caption format defaults to plain text. Not idempotent: each call sends a new document.',
25
+ idempotent: false,
26
+ },
27
+ outputSchema: telegramSendDocumentActionOutputSchema,
28
+ props: {
29
+ chat_id: telegramCommons.chatIdProp(),
30
+ document: Property.File({
31
+ displayName: 'Document',
32
+ description:
33
+ 'The document file to send. Telegram supports any file up to 50 MB. Provide this or a document_id.',
34
+ required: false,
35
+ }),
36
+ document_id: Property.ShortText({
37
+ displayName: 'Document Id',
38
+ description:
39
+ 'Reuse a document previously uploaded to Telegram by passing its file_id. Provide this or a document file.',
40
+ required: false,
41
+ }),
42
+ caption: Property.LongText({
43
+ displayName: 'Caption',
44
+ description: 'Optional caption to display below the document (0–1024 chars).',
45
+ required: false,
46
+ }),
47
+ format: Property.StaticDropdown({
48
+ displayName: 'Caption Format',
49
+ description:
50
+ 'How the caption should be parsed by Telegram. Defaults to plain text; only set MarkdownV2 or HTML when the caption is correctly escaped/tagged.',
51
+ required: false,
52
+ options: {
53
+ options: [
54
+ { label: 'Plain Text', value: 'None' },
55
+ { label: 'Markdown (V2)', value: 'MarkdownV2' },
56
+ { label: 'HTML', value: 'HTML' },
57
+ ],
58
+ },
59
+ defaultValue: 'None',
60
+ }),
61
+ message_thread_id: Property.ShortText({
62
+ displayName: 'Message Thread Id',
63
+ description:
64
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
65
+ required: false,
66
+ }),
67
+ disable_notification: telegramCommons.disableNotificationProp(),
68
+ protect_content: telegramCommons.protectContentProp(),
69
+ reply_to_message_id: telegramCommons.replyToMessageIdProp(),
70
+ reply_markup: Property.Json({
71
+ displayName: 'Reply Markup',
72
+ description:
73
+ 'Advanced/optional. A raw JSON-serialized inline keyboard, e.g. {"inline_keyboard":[[{"text":"Open","url":"https://example.com"}]]}. Malformed markup is rejected by Telegram.',
74
+ required: false,
75
+ }),
76
+ },
77
+ async run(ctx) {
78
+ const file = ctx.propsValue.document as ApFile | undefined;
79
+ const documentId = ctx.propsValue.document_id;
80
+ const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.format);
81
+
82
+ if (!file && !documentId) {
83
+ throw new Error(
84
+ 'Either a document file or a document id must be provided.'
85
+ );
86
+ }
87
+
88
+ const headers: Record<string, string> = {};
89
+ let body: HttpMessageBody;
90
+
91
+ if (file && file.data && file.filename) {
92
+ const form = new FormData();
93
+ form.append('document', file.data, file.filename);
94
+ form.append('chat_id', ctx.propsValue.chat_id);
95
+ if (ctx.propsValue.caption) form.append('caption', ctx.propsValue.caption);
96
+ if (ctx.propsValue.message_thread_id) {
97
+ form.append('message_thread_id', ctx.propsValue.message_thread_id);
98
+ }
99
+ if (parseMode) form.append('parse_mode', parseMode);
100
+ if (ctx.propsValue.disable_notification)
101
+ form.append('disable_notification', 'true');
102
+ if (ctx.propsValue.protect_content)
103
+ form.append('protect_content', 'true');
104
+ if (ctx.propsValue.reply_to_message_id) {
105
+ form.append(
106
+ 'reply_to_message_id',
107
+ String(ctx.propsValue.reply_to_message_id)
108
+ );
109
+ }
110
+ if (ctx.propsValue.reply_markup) {
111
+ form.append('reply_markup', JSON.stringify(ctx.propsValue.reply_markup));
112
+ }
113
+ body = form;
114
+ Object.assign(headers, form.getHeaders());
115
+ } else {
116
+ body = {
117
+ chat_id: ctx.propsValue.chat_id,
118
+ document: documentId,
119
+ caption: ctx.propsValue.caption ?? undefined,
120
+ message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
121
+ parse_mode: parseMode,
122
+ disable_notification: ctx.propsValue.disable_notification ?? false,
123
+ protect_content: ctx.propsValue.protect_content ?? false,
124
+ reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
125
+ reply_markup: ctx.propsValue.reply_markup ?? undefined,
126
+ };
127
+ }
128
+
129
+ return await httpClient.sendRequest<never>({
130
+ method: HttpMethod.POST,
131
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendDocument'),
132
+ headers,
133
+ body,
134
+ });
135
+ },
136
+ });
@@ -0,0 +1,89 @@
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 { telegramSendLocationActionOutputSchema } from '../output-schemas';
6
+
7
+ export const telegramSendLocation = createAction({
8
+ auth: telegramBotAuth,
9
+ name: 'telegram_send_location',
10
+ displayName: 'Send Location',
11
+ description: 'Send a geographic location (latitude/longitude) to a Telegram chat.',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Sends a point location (latitude + longitude) to a chat addressed by chat_id (a numeric id or @channelusername the bot can reach), 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.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: telegramSendLocationActionOutputSchema,
19
+ props: {
20
+ chat_id: telegramCommons.chatIdProp(),
21
+ latitude: Property.Number({
22
+ displayName: 'Latitude',
23
+ description: 'Latitude of the location.',
24
+ required: true,
25
+ }),
26
+ longitude: Property.Number({
27
+ displayName: 'Longitude',
28
+ description: 'Longitude of the location.',
29
+ required: true,
30
+ }),
31
+ horizontal_accuracy: Property.Number({
32
+ displayName: 'Horizontal Accuracy',
33
+ description: 'Radius of uncertainty for the location, in meters (0–1500).',
34
+ required: false,
35
+ }),
36
+ live_period: Property.Number({
37
+ displayName: 'Live Period',
38
+ description:
39
+ 'Number of seconds the location will be updated (60–86400). Use for live locations.',
40
+ required: false,
41
+ }),
42
+ heading: Property.Number({
43
+ displayName: 'Heading',
44
+ description: 'For live locations, direction the user is moving in degrees (1–360).',
45
+ required: false,
46
+ }),
47
+ proximity_alert_radius: Property.Number({
48
+ displayName: 'Proximity Alert Radius',
49
+ description:
50
+ 'For live locations, the max distance (1–100000 m) for proximity alerts about approaching another chat member.',
51
+ required: false,
52
+ }),
53
+ message_thread_id: Property.ShortText({
54
+ displayName: 'Message Thread Id',
55
+ description:
56
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
57
+ required: false,
58
+ }),
59
+ disable_notification: telegramCommons.disableNotificationProp(),
60
+ protect_content: telegramCommons.protectContentProp(),
61
+ reply_to_message_id: telegramCommons.replyToMessageIdProp(),
62
+ reply_markup: Property.Json({
63
+ displayName: 'Reply Markup',
64
+ description:
65
+ 'Advanced/optional. A raw JSON-serialized inline keyboard, e.g. {"inline_keyboard":[[{"text":"Open","url":"https://example.com"}]]}. Malformed markup is rejected by Telegram.',
66
+ required: false,
67
+ }),
68
+ },
69
+ async run(ctx) {
70
+ return await httpClient.sendRequest<never>({
71
+ method: HttpMethod.POST,
72
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendLocation'),
73
+ body: {
74
+ chat_id: ctx.propsValue.chat_id,
75
+ latitude: ctx.propsValue.latitude,
76
+ longitude: ctx.propsValue.longitude,
77
+ message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
78
+ horizontal_accuracy: ctx.propsValue.horizontal_accuracy ?? undefined,
79
+ live_period: ctx.propsValue.live_period ?? undefined,
80
+ heading: ctx.propsValue.heading ?? undefined,
81
+ proximity_alert_radius: ctx.propsValue.proximity_alert_radius ?? undefined,
82
+ disable_notification: ctx.propsValue.disable_notification ?? false,
83
+ protect_content: ctx.propsValue.protect_content ?? false,
84
+ reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
85
+ reply_markup: ctx.propsValue.reply_markup ?? undefined,
86
+ },
87
+ });
88
+ },
89
+ });
@@ -0,0 +1,119 @@
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 { telegramSendMediaGroupActionOutputSchema } 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 telegramSendMediaGroup = createAction({
17
+ auth: telegramBotAuth,
18
+ name: 'telegram_send_media_group',
19
+ displayName: 'Send Media Group (Album)',
20
+ description:
21
+ 'Send a group of 2–10 photos, videos, documents or audios as an album to a chat.',
22
+ audience: 'ai',
23
+ aiMetadata: {
24
+ description:
25
+ 'Sends 2–10 media items (each a public URL or a Telegram file_id) as one grouped album to a chat addressed by chat_id (a numeric id or @channelusername the bot can reach). 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. Item captions default to plain text. For a single item use telegram_send_photo_or_video. Not idempotent: each call posts a new album.',
26
+ idempotent: false,
27
+ },
28
+ outputSchema: telegramSendMediaGroupActionOutputSchema,
29
+ props: {
30
+ chat_id: telegramCommons.chatIdProp(),
31
+ media: Property.Array({
32
+ displayName: 'Media',
33
+ description:
34
+ '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.',
35
+ required: true,
36
+ properties: {
37
+ type: Property.StaticDropdown({
38
+ displayName: 'Type',
39
+ required: true,
40
+ options: {
41
+ options: [
42
+ { label: 'Photo', value: 'photo' },
43
+ { label: 'Video', value: 'video' },
44
+ { label: 'Audio', value: 'audio' },
45
+ { label: 'Document', value: 'document' },
46
+ ],
47
+ },
48
+ defaultValue: 'photo',
49
+ }),
50
+ media: Property.ShortText({
51
+ displayName: 'Media URL or File Id',
52
+ description:
53
+ 'Public URL or a Telegram file_id of an already uploaded media item.',
54
+ required: true,
55
+ }),
56
+ caption: Property.LongText({
57
+ displayName: 'Caption',
58
+ required: false,
59
+ }),
60
+ },
61
+ }),
62
+ parse_mode: Property.StaticDropdown({
63
+ displayName: 'Caption Format',
64
+ description:
65
+ 'How item captions should be parsed by Telegram. Defaults to plain text; only set MarkdownV2 or HTML when captions are correctly escaped/tagged.',
66
+ required: false,
67
+ options: {
68
+ options: [
69
+ { label: 'Plain Text', value: 'None' },
70
+ { label: 'Markdown (V2)', value: 'MarkdownV2' },
71
+ { label: 'HTML', value: 'HTML' },
72
+ ],
73
+ },
74
+ defaultValue: 'None',
75
+ }),
76
+ message_thread_id: Property.ShortText({
77
+ displayName: 'Message Thread Id',
78
+ description:
79
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
80
+ required: false,
81
+ }),
82
+ disable_notification: telegramCommons.disableNotificationProp(),
83
+ protect_content: telegramCommons.protectContentProp(),
84
+ reply_to_message_id: telegramCommons.replyToMessageIdProp(),
85
+ },
86
+ async run(ctx) {
87
+ const items = (ctx.propsValue.media ?? []) as Array<Record<string, unknown>>;
88
+ if (items.length < 2 || items.length > MEDIA_GROUP_LIMIT) {
89
+ throw new Error('A media group must contain 2–10 media items.');
90
+ }
91
+ const parseMode = telegramCommons.resolveParseMode(ctx.propsValue.parse_mode);
92
+
93
+ const media: MediaItem[] = items.map((item) => {
94
+ const type = String(item['type'] ?? 'photo') as MediaItem['type'];
95
+ const value = String(item['media'] ?? '');
96
+ if (!value) {
97
+ throw new Error('Each media item must define a URL or file_id.');
98
+ }
99
+ const caption = item['caption'] ? String(item['caption']) : undefined;
100
+ const mediaItem: MediaItem = { type, media: value };
101
+ if (caption) mediaItem.caption = caption;
102
+ if (caption && parseMode) mediaItem.parse_mode = parseMode;
103
+ return mediaItem;
104
+ });
105
+
106
+ return await httpClient.sendRequest<never>({
107
+ method: HttpMethod.POST,
108
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendMediaGroup'),
109
+ body: {
110
+ chat_id: ctx.propsValue.chat_id,
111
+ message_thread_id: ctx.propsValue.message_thread_id ?? undefined,
112
+ media,
113
+ disable_notification: ctx.propsValue.disable_notification ?? false,
114
+ protect_content: ctx.propsValue.protect_content ?? false,
115
+ reply_to_message_id: ctx.propsValue.reply_to_message_id ?? undefined,
116
+ },
117
+ });
118
+ },
119
+ });
@@ -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 { telegramSendMessageActionOutputSchema } from '../output-schemas';
6
+
7
+ export const telegramSendMessage = createAction({
8
+ auth: telegramBotAuth,
9
+ name: 'telegram_send_message',
10
+ displayName: 'Send Message',
11
+ description: 'Send a text message to a Telegram chat, group, or channel.',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Posts a text message to a Telegram chat, group, or channel addressed by chat_id (a numeric id or @channelusername the bot can reach — resolve via the New Message trigger payload\'s chat.id or telegram_get_chat). Use to deliver a notification, reply, or alert; for an attachment use telegram_send_document, for a photo/video use telegram_send_photo_or_video. Text is sent as plain text unless format is set; if you set MarkdownV2 or HTML the text must be correctly escaped or Telegram rejects it. reply_markup is an advanced raw inline-keyboard JSON object. Not idempotent: each call sends a new message.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: telegramSendMessageActionOutputSchema,
19
+ props: {
20
+ chat_id: telegramCommons.chatIdProp(),
21
+ message: Property.LongText({
22
+ displayName: 'Message',
23
+ description: 'The text message to send.',
24
+ required: true,
25
+ }),
26
+ format: Property.StaticDropdown({
27
+ displayName: 'Format',
28
+ description:
29
+ 'How the message text should be parsed by Telegram. Defaults to plain text; only set MarkdownV2 or HTML when the text is correctly escaped/tagged.',
30
+ required: false,
31
+ options: {
32
+ options: [
33
+ { label: 'Plain Text', value: 'None' },
34
+ { label: 'Markdown (V2)', value: 'MarkdownV2' },
35
+ { label: 'HTML', value: 'HTML' },
36
+ ],
37
+ },
38
+ defaultValue: 'None',
39
+ }),
40
+ message_thread_id: Property.ShortText({
41
+ displayName: 'Message Thread Id',
42
+ description:
43
+ 'Unique identifier for the target message thread of the forum; supergroup forums only.',
44
+ required: false,
45
+ }),
46
+ web_page_preview: Property.Checkbox({
47
+ displayName: 'Disable Web Page Preview',
48
+ description: 'Disable link previews for links in this message.',
49
+ required: false,
50
+ defaultValue: false,
51
+ }),
52
+ disable_notification: telegramCommons.disableNotificationProp(),
53
+ protect_content: telegramCommons.protectContentProp(),
54
+ reply_to_message_id: telegramCommons.replyToMessageIdProp(),
55
+ reply_markup: Property.Json({
56
+ displayName: 'Reply Markup',
57
+ description:
58
+ 'Advanced/optional. A raw JSON-serialized inline keyboard or reply keyboard, e.g. {"inline_keyboard":[[{"text":"Open","url":"https://example.com"}]]}. Malformed markup is rejected by Telegram.',
59
+ required: false,
60
+ }),
61
+ },
62
+ async run(ctx) {
63
+ return await httpClient.sendRequest<never>({
64
+ method: HttpMethod.POST,
65
+ url: telegramCommons.getApiUrl(ctx.auth, 'sendMessage'),
66
+ body: {
67
+ chat_id: ctx.propsValue['chat_id'],
68
+ text: ctx.propsValue['message'],
69
+ message_thread_id: ctx.propsValue['message_thread_id'] ?? undefined,
70
+ parse_mode: telegramCommons.resolveParseMode(ctx.propsValue['format']),
71
+ reply_markup: ctx.propsValue['reply_markup'] ?? undefined,
72
+ disable_web_page_preview: ctx.propsValue['web_page_preview'] ?? false,
73
+ disable_notification: ctx.propsValue['disable_notification'] ?? false,
74
+ protect_content: ctx.propsValue['protect_content'] ?? false,
75
+ reply_to_message_id: ctx.propsValue['reply_to_message_id'] ?? undefined,
76
+ },
77
+ });
78
+ },
79
+ });