@pipedream/telegram_bot_api 0.3.3

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 (36) hide show
  1. package/LICENSE +7 -0
  2. package/actions/create-chat-invite-link/create-chat-invite-link.mjs +52 -0
  3. package/actions/delete-message/delete-message.mjs +29 -0
  4. package/actions/edit-media-message/edit-media-message.mjs +89 -0
  5. package/actions/edit-text-message/edit-text-message.mjs +45 -0
  6. package/actions/export-chat-invite-link/export-chat-invite-link.mjs +23 -0
  7. package/actions/forward-message/forward-message.mjs +48 -0
  8. package/actions/get-num-members-in-chat/get-num-members-in-chat.mjs +23 -0
  9. package/actions/kick-chat-member/kick-chat-member.mjs +38 -0
  10. package/actions/list-administrators-in-chat/list-administrators-in-chat.mjs +25 -0
  11. package/actions/list-chats/list-chats.mjs +73 -0
  12. package/actions/list-updates/list-updates.mjs +49 -0
  13. package/actions/pin-message/pin-message.mjs +37 -0
  14. package/actions/promote-chat-member/promote-chat-member.mjs +86 -0
  15. package/actions/restrict-chat-member/restrict-chat-member.mjs +66 -0
  16. package/actions/send-album/send-album.mjs +53 -0
  17. package/actions/send-audio-file/send-audio-file.mjs +98 -0
  18. package/actions/send-document-or-image/send-document-or-image.mjs +83 -0
  19. package/actions/send-media-by-url-or-id/send-media-by-url-or-id.mjs +73 -0
  20. package/actions/send-photo/send-photo.mjs +84 -0
  21. package/actions/send-sticker/send-sticker.mjs +53 -0
  22. package/actions/send-text-message-or-reply/send-text-message-or-reply.mjs +66 -0
  23. package/actions/send-video/send-video.mjs +86 -0
  24. package/actions/send-video-note/send-video-note.mjs +76 -0
  25. package/actions/send-voice-message/send-voice-message.mjs +85 -0
  26. package/actions/unpin-message/unpin-message.mjs +29 -0
  27. package/constants.mjs +198 -0
  28. package/content-types.mjs +115 -0
  29. package/env.mjs +14 -0
  30. package/package.json +21 -0
  31. package/sources/channel-updates/channel-updates.mjs +50 -0
  32. package/sources/message-updates/message-updates.mjs +50 -0
  33. package/sources/new-updates/new-updates.mjs +63 -0
  34. package/telegram_bot_api.app.mjs +682 -0
  35. package/update-types.mjs +50 -0
  36. package/utils.mjs +27 -0
@@ -0,0 +1,76 @@
1
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
+ import contentTypes from "../../content-types.mjs";
3
+
4
+ export default {
5
+ key: "telegram_bot_api-send-video-note",
6
+ name: "Send a Video Note",
7
+ description: "As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. [See the docs](https://core.telegram.org/bots/api#sendvideonote) for more information",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ telegramBotApi,
12
+ chatId: {
13
+ propDefinition: [
14
+ telegramBotApi,
15
+ "chatId",
16
+ ],
17
+ },
18
+ filename: {
19
+ propDefinition: [
20
+ telegramBotApi,
21
+ "filename",
22
+ ],
23
+ },
24
+ videoNote: {
25
+ propDefinition: [
26
+ telegramBotApi,
27
+ "media",
28
+ ],
29
+ label: "Video Note",
30
+ },
31
+ contentType: {
32
+ propDefinition: [
33
+ telegramBotApi,
34
+ "contentType",
35
+ ],
36
+ options: contentTypes.video,
37
+ },
38
+ length: {
39
+ propDefinition: [
40
+ telegramBotApi,
41
+ "length",
42
+ ],
43
+ },
44
+ duration: {
45
+ propDefinition: [
46
+ telegramBotApi,
47
+ "duration",
48
+ ],
49
+ },
50
+ reply_to_message_id: {
51
+ propDefinition: [
52
+ telegramBotApi,
53
+ "reply_to_message_id",
54
+ ],
55
+ },
56
+ reply_markup: {
57
+ propDefinition: [
58
+ telegramBotApi,
59
+ "reply_markup",
60
+ ],
61
+ },
62
+ },
63
+ async run({ $ }) {
64
+ const resp = await this.telegramBotApi.sendVideoNote(this.chatId, this.videoNote, {
65
+ length: this.length,
66
+ duration: this.duration,
67
+ reply_to_message_id: this.reply_to_message_id,
68
+ reply_markup: this.reply_markup,
69
+ filename: this.filename,
70
+ contentType: this.contentType,
71
+ });
72
+ // eslint-disable-next-line multiline-ternary
73
+ $.export("$summary", `Successfully sent the video note${this.fileName ? ` "${this.filename}"` : ""} to chat, "${this.chatId}"`);
74
+ return resp;
75
+ },
76
+ };
@@ -0,0 +1,85 @@
1
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
+ import contentTypes from "../../content-types.mjs";
3
+
4
+ export default {
5
+ key: "telegram_bot_api-send-voice-message",
6
+ name: "Send a Voice Message",
7
+ description: "Sends a voice message. [See the docs](https://core.telegram.org/bots/api#sendvoice) for more information",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ telegramBotApi,
12
+ chatId: {
13
+ propDefinition: [
14
+ telegramBotApi,
15
+ "chatId",
16
+ ],
17
+ },
18
+ caption: {
19
+ propDefinition: [
20
+ telegramBotApi,
21
+ "caption",
22
+ ],
23
+ description: "Enter the voice message caption.",
24
+ },
25
+ filename: {
26
+ propDefinition: [
27
+ telegramBotApi,
28
+ "filename",
29
+ ],
30
+ },
31
+ voice: {
32
+ propDefinition: [
33
+ telegramBotApi,
34
+ "media",
35
+ ],
36
+ label: "Voice Message",
37
+ },
38
+ parse_mode: {
39
+ propDefinition: [
40
+ telegramBotApi,
41
+ "parse_mode",
42
+ ],
43
+ },
44
+ disable_notification: {
45
+ propDefinition: [
46
+ telegramBotApi,
47
+ "disable_notification",
48
+ ],
49
+ },
50
+ contentType: {
51
+ propDefinition: [
52
+ telegramBotApi,
53
+ "contentType",
54
+ ],
55
+ options: contentTypes.voice,
56
+ },
57
+ duration: {
58
+ propDefinition: [
59
+ telegramBotApi,
60
+ "duration",
61
+ ],
62
+ description: "Enter the duration of sent voice message in seconds.",
63
+ },
64
+ reply_markup: {
65
+ propDefinition: [
66
+ telegramBotApi,
67
+ "reply_markup",
68
+ ],
69
+ },
70
+ },
71
+ async run({ $ }) {
72
+ const resp = await this.telegramBotApi.sendAudio(this.chatId, this.voice, {
73
+ caption: this.caption,
74
+ parse_mode: this.parse_mode,
75
+ disable_notification: this.disable_notification,
76
+ duration: this.duration,
77
+ reply_markup: this.reply_markup,
78
+ filename: this.filename,
79
+ contentType: this.contentType,
80
+ });
81
+ // eslint-disable-next-line multiline-ternary
82
+ $.export("$summary", `Successfully sent the voice message${this.fileName ? ` "${this.filename}"` : ""} to chat, "${this.chatId}"`);
83
+ return resp;
84
+ },
85
+ };
@@ -0,0 +1,29 @@
1
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
+
3
+ export default {
4
+ key: "telegram_bot_api-unpin-message",
5
+ name: "Unpin a Message",
6
+ description: "Unpins a message. [See the docs](https://core.telegram.org/bots/api#unpinchatmessage) for more information",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ telegramBotApi,
11
+ chatId: {
12
+ propDefinition: [
13
+ telegramBotApi,
14
+ "chatId",
15
+ ],
16
+ },
17
+ messageId: {
18
+ propDefinition: [
19
+ telegramBotApi,
20
+ "messageId",
21
+ ],
22
+ },
23
+ },
24
+ async run({ $ }) {
25
+ const resp = await this.telegramBotApi.unpinChatMessage(this.chatId, this.messageId);
26
+ $.export("$summary", `Successfully unpinned the message from chat, "${this.chatId}"`);
27
+ return resp;
28
+ },
29
+ };
package/constants.mjs ADDED
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @typedef {string} MediaType - a type of media as defined by
3
+ * the [Telegram Bot API docs](https://bit.ly/3m7rjsc)
4
+ */
5
+
6
+ /**
7
+ * Represents a photo to be sent
8
+ *
9
+ * @type {MediaType}
10
+ */
11
+ const TELEGRAM_BOT_API_MEDIA_PHOTO = "photo";
12
+
13
+ /**
14
+ * Represents a video to be sent
15
+ *
16
+ * @type {MediaType}
17
+ */
18
+ const TELEGRAM_BOT_API_MEDIA_VIDEO = "video";
19
+
20
+ /**
21
+ * Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent
22
+ *
23
+ * @type {MediaType}
24
+ */
25
+ const TELEGRAM_BOT_API_MEDIA_ANIMATION = "animation";
26
+
27
+ /**
28
+ * Represents an audio file to be treated as music to be sent
29
+ *
30
+ * @type {MediaType}
31
+ */
32
+ const TELEGRAM_BOT_API_MEDIA_AUDIO = "audio";
33
+
34
+ /**
35
+ * Represents a general file to be sent
36
+ *
37
+ * @type {MediaType}
38
+ */
39
+ const TELEGRAM_BOT_API_MEDIA_DOCUMENT = "document";
40
+
41
+ /**
42
+ * All the available Telegram Bot media types
43
+ * @type {MediaType[]}
44
+ */
45
+ const TELEGRAM_BOT_API_MEDIA_TYPES = [
46
+ TELEGRAM_BOT_API_MEDIA_PHOTO,
47
+ TELEGRAM_BOT_API_MEDIA_VIDEO,
48
+ TELEGRAM_BOT_API_MEDIA_ANIMATION,
49
+ TELEGRAM_BOT_API_MEDIA_AUDIO,
50
+ TELEGRAM_BOT_API_MEDIA_DOCUMENT,
51
+ ];
52
+
53
+ /**
54
+ * @typedef {string} UIMediaType - a type of media shown to users as part of the UI
55
+ */
56
+
57
+ /**
58
+ * Represents a document or image
59
+ *
60
+ * @type {UIMediaType}
61
+ */
62
+ const TELEGRAM_BOT_API_UI_MEDIA_DOCUMENT = "Document/Image";
63
+
64
+ /**
65
+ * Represents a photo
66
+ *
67
+ * @type {UIMediaType}
68
+ */
69
+ const TELEGRAM_BOT_API_UI_MEDIA_PHOTO = "Photo";
70
+
71
+ /**
72
+ * Represents an audio file to be treated as music
73
+ *
74
+ * @type {UIMediaType}
75
+ */
76
+ const TELEGRAM_BOT_API_UI_MEDIA_AUDIO = "Audio";
77
+
78
+ /**
79
+ * Represents a video
80
+ *
81
+ * @type {UIMediaType}
82
+ */
83
+ const TELEGRAM_BOT_API_UI_MEDIA_VIDEO = "Video";
84
+
85
+ /**
86
+ * Represents a video note
87
+ *
88
+ * @type {UIMediaType}
89
+ */
90
+ const TELEGRAM_BOT_API_UI_MEDIA_VIDEO_NOTE = "Video Note";
91
+
92
+ /**
93
+ * Represents a voice message
94
+ *
95
+ * @type {UIMediaType}
96
+ */
97
+ const TELEGRAM_BOT_API_UI_MEDIA_VOICE = "Voice";
98
+
99
+ /**
100
+ * Represents a sticker
101
+ *
102
+ * @type {UIMediaType}
103
+ */
104
+ const TELEGRAM_BOT_API_UI_MEDIA_STICKER = "Sticker";
105
+
106
+ /**
107
+ * All the available Telegram Bot UI media types
108
+ * @type {UIMediaType[]}
109
+ */
110
+ const TELEGRAM_BOT_API_UI_MEDIA_TYPES = [
111
+ TELEGRAM_BOT_API_UI_MEDIA_DOCUMENT,
112
+ TELEGRAM_BOT_API_UI_MEDIA_PHOTO,
113
+ TELEGRAM_BOT_API_UI_MEDIA_AUDIO,
114
+ TELEGRAM_BOT_API_UI_MEDIA_VIDEO,
115
+ TELEGRAM_BOT_API_UI_MEDIA_VIDEO_NOTE,
116
+ TELEGRAM_BOT_API_UI_MEDIA_VOICE,
117
+ TELEGRAM_BOT_API_UI_MEDIA_STICKER,
118
+ ];
119
+
120
+ /**
121
+ * @typedef {string} FormattingMode - a formatting mode used to parse entities in text, as defined
122
+ * by the [Telegram Bot API docs](@see{@link https://core.telegram.org/bots/api#formatting-options})
123
+ */
124
+
125
+ /**
126
+ * Mode used to parse text using MarkdownV2 style
127
+ *
128
+ * @example
129
+ * *bold \*text*
130
+ * _italic \*text_
131
+ * __underline__
132
+ * ~strikethrough~
133
+ * *bold _italic bold ~italic bold strikethrough~ __underline italic bold___ bold*
134
+ * [inline URL](http://www.example.com/)
135
+ *
136
+ * @type {FormattingMode}
137
+ */
138
+ const TELEGRAM_BOT_API_MARKDOWNV2_STYLE = "MarkdownV2";
139
+
140
+ /**
141
+ * Mode used to parse text using HTML style
142
+ *
143
+ * @example
144
+ * <b>bold</b>, <strong>bold</strong> <i>italic</i>, <em>italic</em> <u>underline</u>,
145
+ * <ins>underline</ins> <s>strikethrough</s>, <strike>strikethrough</strike>,
146
+ * <del>strikethrough</del> <b>bold <i>italic bold <s>italic bold strikethrough</s> <u>underline
147
+ * italic bold</u></i> bold</b>
148
+ *
149
+ * @type {FormattingMode}
150
+ */
151
+ const TELEGRAM_BOT_API_HTML_STYLE = "HTML";
152
+
153
+ /**
154
+ * Mode used to parse text using Markdown style
155
+ *
156
+ * @example
157
+ * *bold text*
158
+ * _italic text_
159
+ * [inline URL](http://www.example.com/)
160
+ * [inline mention of a user](tg://user?id=123456789)
161
+ * `inline fixed-width code`
162
+ *
163
+ * @type {FormattingMode}
164
+ */
165
+ const TELEGRAM_BOT_API_MARKDOWN_STYLE = "Markdown";
166
+
167
+ /**
168
+ * All the available Telegram Bot formatting modes
169
+ * @type {FormattingMode[]}
170
+ */
171
+ const TELEGRAM_BOT_API_FORMATTING_MODES = [
172
+ TELEGRAM_BOT_API_MARKDOWNV2_STYLE,
173
+ TELEGRAM_BOT_API_HTML_STYLE,
174
+ TELEGRAM_BOT_API_MARKDOWN_STYLE,
175
+ ];
176
+
177
+ export {
178
+ // Media types
179
+ TELEGRAM_BOT_API_MEDIA_PHOTO,
180
+ TELEGRAM_BOT_API_MEDIA_VIDEO,
181
+ TELEGRAM_BOT_API_MEDIA_ANIMATION,
182
+ TELEGRAM_BOT_API_MEDIA_AUDIO,
183
+ TELEGRAM_BOT_API_MEDIA_DOCUMENT,
184
+ // Array of media types
185
+ TELEGRAM_BOT_API_MEDIA_TYPES,
186
+ // UI media types
187
+ TELEGRAM_BOT_API_UI_MEDIA_DOCUMENT,
188
+ TELEGRAM_BOT_API_UI_MEDIA_PHOTO,
189
+ TELEGRAM_BOT_API_UI_MEDIA_AUDIO,
190
+ TELEGRAM_BOT_API_UI_MEDIA_VIDEO,
191
+ TELEGRAM_BOT_API_UI_MEDIA_VIDEO_NOTE,
192
+ TELEGRAM_BOT_API_UI_MEDIA_VOICE,
193
+ TELEGRAM_BOT_API_UI_MEDIA_STICKER,
194
+ // Array of UI media types
195
+ TELEGRAM_BOT_API_UI_MEDIA_TYPES,
196
+ // Array of formatting modes
197
+ TELEGRAM_BOT_API_FORMATTING_MODES,
198
+ };
@@ -0,0 +1,115 @@
1
+ const image = [
2
+ {
3
+ label: "Gif Images",
4
+ value: "image/gif",
5
+ },
6
+ {
7
+ label: "JPG Images",
8
+ value: "image/jpeg",
9
+ },
10
+ {
11
+ label: "PNG Images",
12
+ value: "image/png",
13
+ },
14
+ {
15
+ label: "Bitmap Images",
16
+ value: "image/bmp",
17
+ },
18
+ {
19
+ label: "Vector Images",
20
+ value: "image/svg+xml",
21
+ },
22
+ ];
23
+
24
+ const video = [
25
+ {
26
+ label: "Video - MPEG",
27
+ value: "video/mpeg",
28
+ },
29
+ {
30
+ label: "Video - MP4",
31
+ value: "video/mp4",
32
+ },
33
+ {
34
+ label: "Video - WebM",
35
+ value: "video/webm",
36
+ },
37
+ {
38
+ label: "Video - OGG",
39
+ value: "video/ogg",
40
+ },
41
+ ];
42
+
43
+ const audio = [
44
+ {
45
+ label: "Audio - MPEG",
46
+ value: "audio/mpeg",
47
+ },
48
+ {
49
+ label: "Audio - Midi",
50
+ value: "audio/mid",
51
+ },
52
+ {
53
+ label: "Audio - WebM",
54
+ value: "audio/webm",
55
+ },
56
+ {
57
+ label: "Audio - OGG",
58
+ value: "audio/ogg",
59
+ },
60
+ {
61
+ label: "Audio - Wave",
62
+ value: "audio/vnd.wav",
63
+ },
64
+ ];
65
+
66
+ const voice = [
67
+ ...audio,
68
+ {
69
+ label: "Video - MP4",
70
+ value: "video/mp4",
71
+ },
72
+ {
73
+ label: "Video - WebM",
74
+ value: "video/webm",
75
+ },
76
+ {
77
+ label: "Video - OGG",
78
+ value: "video/ogg",
79
+ },
80
+ ];
81
+
82
+ const document = [
83
+ {
84
+ label: "Plain Text",
85
+ value: "text/plain",
86
+ },
87
+ {
88
+ label: "HTML Data",
89
+ value: "text/html",
90
+ },
91
+ {
92
+ label: "XML Files",
93
+ value: "application/xml",
94
+ },
95
+ {
96
+ label: "PDF Files",
97
+ value: "application/pdf",
98
+ },
99
+ ];
100
+
101
+ const all = [
102
+ ...document,
103
+ ...image,
104
+ ...video,
105
+ ...audio,
106
+ ];
107
+
108
+ export default {
109
+ image,
110
+ video,
111
+ audio,
112
+ voice,
113
+ document,
114
+ all,
115
+ };
package/env.mjs ADDED
@@ -0,0 +1,14 @@
1
+ // Environment variables are set in this file rather than `telegram_bot_api.app.mjs` because
2
+ // Javascript imports are hoisted, so imported modules will initialize before any of the current
3
+ // modules initialization code gets to run. We want these env vars to be set before other imported
4
+ // modules (specifically 'node-telegram-bot-api') are initialized.
5
+
6
+ // If unset, set `process.env.NTBA_FIX_319` to true to enable cancellation of
7
+ // Promises. See: https://github.com/yagop/node-telegram-bot-api/issues/319 for
8
+ // more information.
9
+ process.env.NTBA_FIX_319 = process.env.NTBA_FIX_319 ?? true;
10
+
11
+ // If unset, set `process.env.NTBA_FIX_350` to true to enable automatic resolution of `filename`
12
+ // and `contentType` properties. See: https://github.com/yagop/node-telegram-bot-api/issues/350
13
+ // for more information.
14
+ process.env.NTBA_FIX_350 = process.env.NTBA_FIX_350 ?? true;
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@pipedream/telegram_bot_api",
3
+ "version": "0.3.3",
4
+ "description": "Pipedream Telegram_bot_api Components",
5
+ "main": "telegram_bot_api.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "telegram_bot_api"
9
+ ],
10
+ "homepage": "https://pipedream.com/apps/telegram_bot_api",
11
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
+ "license": "MIT",
13
+ "dependencies": {
14
+ "@pipedream/platform": "^0.9.0",
15
+ "node-telegram-bot-api": "^0.54.0"
16
+ },
17
+ "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
18
+ "publishConfig": {
19
+ "access": "public"
20
+ }
21
+ }
@@ -0,0 +1,50 @@
1
+ // eslint-disable-next-line camelcase
2
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
3
+
4
+ export default {
5
+ type: "source",
6
+ key: "telegram_bot_api-channel-updates",
7
+ name: "Channel Updates (Instant)",
8
+ description: "Emit new event each time a channel message is created or updated.",
9
+ version: "0.0.3",
10
+ dedupe: "unique",
11
+ props: {
12
+ db: "$.service.db",
13
+ // eslint-disable-next-line pipedream/props-label,pipedream/props-description
14
+ http: {
15
+ type: "$.interface.http",
16
+ customResponse: true,
17
+ },
18
+ telegramBotApi,
19
+ },
20
+ hooks: {
21
+ async activate() {
22
+ await this.telegramBotApi.createHook(this.http.endpoint, [
23
+ "channel_post",
24
+ "edited_channel_post",
25
+ ]);
26
+ },
27
+ async deactivate() {
28
+ await this.telegramBotApi.deleteHook();
29
+ },
30
+ },
31
+ async run(event) {
32
+ if ((event.path).substring(1) !== this.telegramBotApi.$auth.token) {
33
+ return;
34
+ }
35
+ this.http.respond({
36
+ status: 200,
37
+ });
38
+ const { body } = event;
39
+ if (!body) {
40
+ return;
41
+ }
42
+ const channelPost = body.edited_channel_post ?? body.channel_post;
43
+ this.$emit(body,
44
+ {
45
+ id: body.update_id,
46
+ summary: `${channelPost.chat.title} - ${channelPost.text}`,
47
+ ts: Date.now(),
48
+ });
49
+ },
50
+ };
@@ -0,0 +1,50 @@
1
+ // eslint-disable-next-line camelcase
2
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
3
+
4
+ export default {
5
+ type: "source",
6
+ key: "telegram_bot_api-message-updates",
7
+ name: "Message Updates (Instant)",
8
+ description: "Emit new event each time a Telegram message is created or updated.",
9
+ version: "0.0.3",
10
+ dedupe: "unique",
11
+ props: {
12
+ db: "$.service.db",
13
+ // eslint-disable-next-line pipedream/props-label,pipedream/props-description
14
+ http: {
15
+ type: "$.interface.http",
16
+ customResponse: true,
17
+ },
18
+ telegramBotApi,
19
+ },
20
+ hooks: {
21
+ async activate() {
22
+ await this.telegramBotApi.createHook(this.http.endpoint, [
23
+ "message",
24
+ "edited_message",
25
+ ]);
26
+ },
27
+ async deactivate() {
28
+ await this.telegramBotApi.deleteHook();
29
+ },
30
+ },
31
+ async run(event) {
32
+ if ((event.path).substring(1) !== this.telegramBotApi.$auth.token) {
33
+ return;
34
+ }
35
+ this.http.respond({
36
+ status: 200,
37
+ });
38
+ const { body } = event;
39
+ if (!body) {
40
+ return;
41
+ }
42
+ const message = body.edited_message ?? body.message;
43
+ this.$emit(body,
44
+ {
45
+ id: body.update_id,
46
+ summary: message.text,
47
+ ts: Date.now(),
48
+ });
49
+ },
50
+ };
@@ -0,0 +1,63 @@
1
+ // eslint-disable-next-line camelcase
2
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
3
+
4
+ export default {
5
+ key: "telegram_bot_api-new-updates",
6
+ name: "New Updates (Instant)",
7
+ description: "Emit new event for each new Telegram event.",
8
+ version: "0.0.3",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ db: "$.service.db",
13
+ // eslint-disable-next-line pipedream/props-label,pipedream/props-description
14
+ http: {
15
+ label: "HTTP Responder",
16
+ description: "Exposes a `respond()` method that lets the source issue HTTP responses",
17
+ type: "$.interface.http",
18
+ customResponse: true,
19
+ },
20
+ telegramBotApi,
21
+ updateTypes: {
22
+ propDefinition: [
23
+ telegramBotApi, // eslint-disable-line camelcase
24
+ "updateTypes",
25
+ ],
26
+ },
27
+ },
28
+ hooks: {
29
+ async activate() {
30
+ await this.telegramBotApi.createHook(this.http.endpoint, this.updateTypes);
31
+ },
32
+ async deactivate() {
33
+ await this.telegramBotApi.deleteHook();
34
+ },
35
+ },
36
+ methods: {
37
+ getMeta(body) {
38
+ let summary;
39
+ if (body.message.from)
40
+ summary = `Update from ${body.message.from.first_name} ${body.message.from.last_name}`;
41
+ else
42
+ summary = `Update ID ${body.update_id}`;
43
+ return {
44
+ id: body.update_id,
45
+ summary,
46
+ ts: Date.now(),
47
+ };
48
+ },
49
+ },
50
+ async run(event) {
51
+ if ((event.path).substring(1) !== this.telegramBotApi.$auth.token) {
52
+ return;
53
+ }
54
+ this.http.respond({
55
+ status: 200,
56
+ });
57
+ const { body } = event;
58
+ if (!body) {
59
+ return;
60
+ }
61
+ this.$emit(body, this.getMeta(body));
62
+ },
63
+ };