@pipedream/telegram_bot_api 0.3.3 → 0.3.4

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 (38) hide show
  1. package/actions/create-chat-invite-link/create-chat-invite-link.mjs +1 -1
  2. package/actions/delete-message/delete-message.mjs +1 -1
  3. package/actions/edit-media-message/edit-media-message.mjs +2 -2
  4. package/actions/edit-text-message/edit-text-message.mjs +1 -1
  5. package/actions/export-chat-invite-link/export-chat-invite-link.mjs +1 -1
  6. package/actions/forward-message/forward-message.mjs +1 -1
  7. package/actions/get-num-members-in-chat/get-num-members-in-chat.mjs +1 -1
  8. package/actions/kick-chat-member/kick-chat-member.mjs +1 -1
  9. package/actions/list-administrators-in-chat/list-administrators-in-chat.mjs +1 -1
  10. package/actions/list-chats/list-chats.mjs +1 -1
  11. package/actions/list-updates/list-updates.mjs +1 -1
  12. package/actions/pin-message/pin-message.mjs +1 -1
  13. package/actions/promote-chat-member/promote-chat-member.mjs +1 -1
  14. package/actions/restrict-chat-member/restrict-chat-member.mjs +1 -1
  15. package/actions/send-album/send-album.mjs +2 -2
  16. package/actions/send-audio-file/send-audio-file.mjs +2 -2
  17. package/actions/send-document-or-image/send-document-or-image.mjs +2 -2
  18. package/actions/send-media-by-url-or-id/send-media-by-url-or-id.mjs +2 -2
  19. package/actions/send-photo/send-photo.mjs +2 -2
  20. package/actions/send-sticker/send-sticker.mjs +1 -1
  21. package/actions/send-text-message-or-reply/send-text-message-or-reply.mjs +1 -1
  22. package/actions/send-video/send-video.mjs +2 -2
  23. package/actions/send-video-note/send-video-note.mjs +2 -2
  24. package/actions/send-voice-message/send-voice-message.mjs +2 -2
  25. package/actions/set-chat-permissions/set-chat-permissions.mjs +88 -0
  26. package/actions/unpin-message/unpin-message.mjs +1 -1
  27. package/{constants.mjs → common/constants.mjs} +0 -0
  28. package/{content-types.mjs → common/content-types.mjs} +0 -0
  29. package/{env.mjs → common/env.mjs} +0 -0
  30. package/{update-types.mjs → common/update-types.mjs} +12 -0
  31. package/{utils.mjs → common/utils.mjs} +0 -0
  32. package/package.json +3 -2
  33. package/sources/channel-updates/channel-updates.mjs +26 -40
  34. package/sources/common/constants.mjs +3 -0
  35. package/sources/common/webhooks.mjs +79 -0
  36. package/sources/message-updates/message-updates.mjs +19 -38
  37. package/sources/new-updates/new-updates.mjs +23 -42
  38. package/telegram_bot_api.app.mjs +23 -6
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-create-chat-invite-link",
5
5
  name: "Create Chat Invite Link",
6
6
  description: "Create an additional invite link for a chat, [See the docs](https://core.telegram.org/bots/api#createchatinvitelink) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-delete-message",
5
5
  name: "Delete a Message",
6
6
  description: "Deletes a message. [See the docs](https://core.telegram.org/bots/api#deletemessage) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  TELEGRAM_BOT_API_MEDIA_PHOTO,
3
3
  TELEGRAM_BOT_API_MEDIA_VIDEO,
4
- } from "../../constants.mjs";
4
+ } from "../../common/constants.mjs";
5
5
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
6
6
 
7
7
  export default {
8
8
  key: "telegram_bot_api-edit-media-message",
9
9
  name: "Edit a Media Message",
10
10
  description: "Edits photo or video messages. [See the docs](https://core.telegram.org/bots/api#editmessagemedia) for more information",
11
- version: "0.0.1",
11
+ version: "0.0.3",
12
12
  type: "action",
13
13
  props: {
14
14
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-edit-text-message",
5
5
  name: "Edit a Text Message",
6
6
  description: "Edits text or game messages. [See the docs](https://core.telegram.org/bots/api#editmessagetext) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-export-chat-invite-link",
5
5
  name: "Export Chat Invite Link",
6
6
  description: "Generate a new primary invite link for a chat, [See the docs](https://core.telegram.org/bots/api#createchatinvitelink) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-forward-message",
5
5
  name: "Forward a Message",
6
6
  description: "Forwards messages of any kind. [See the docs](https://core.telegram.org/bots/api#forwardmessage) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-get-num-members-in-chat",
5
5
  name: "Get the Number of Members in a Chat",
6
6
  description: "Use this module to get the number of members in a chat. [See the docs](https://core.telegram.org/bots/api#getchatmembercount) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-kick-chat-member",
5
5
  name: "Kick a Chat Member",
6
6
  description: "Use this method to kick a user from a group, a supergroup or channel. [See the docs](https://core.telegram.org/bots/api#banchatmember) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-list-administrators-in-chat",
5
5
  name: "List Administrators In Chat",
6
6
  description: "Use this module to get a list of administrators in a chat. [See the docs](https://core.telegram.org/bots/api#getchatadministrators) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-list-chats",
5
5
  name: "List Chats",
6
6
  description: "List available Telegram chats. [See the docs](https://core.telegram.org/bots/api#getupdates) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-list-updates",
5
5
  name: "List Updates",
6
6
  description: "Retrieves a list of updates from the Telegram server. [See the docs](https://core.telegram.org/bots/api#getupdates) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-pin-message",
5
5
  name: "Pin a Message",
6
6
  description: "Pins a message. [See the docs](https://core.telegram.org/bots/api#pinchatmessage) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-promote-chat-member",
5
5
  name: "Promote a Chat Member",
6
6
  description: "Use this method to promote or demote a user in a supergroup or a channel. [See the docs](https://core.telegram.org/bots/api#promotechatmember) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-restrict-chat-member",
5
5
  name: "Restrict a Chat Member",
6
6
  description: "Use this method to restrict a user in a supergroup. [See the docs](https://core.telegram.org/bots/api#restrictchatmember) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import { toSingleLineString } from "../../utils.mjs";
2
+ import { toSingleLineString } from "../../common/utils.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-album",
6
6
  name: "Send an Album (Media Group)",
7
7
  description: "Sends a group of photos or videos as an album. [See the docs](https://core.telegram.org/bots/api#sendmediagroup) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-audio-file",
6
6
  name: "Send an Audio File",
7
7
  description: "Sends an audio file to your Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#sendaudio) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-document-or-image",
6
6
  name: "Send a Document/Image",
7
7
  description: "Sends a document or an image to your Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#senddocument) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import { TELEGRAM_BOT_API_UI_MEDIA_TYPES } from "../../constants.mjs";
2
+ import { TELEGRAM_BOT_API_UI_MEDIA_TYPES } from "../../common/constants.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-media-by-url-or-id",
6
6
  name: "Send Media by URL or ID",
7
7
  description: "Sends a file (document, photo, video, audio, ...) by HTTP URL or by ID that exists on the Telegram servers. [See the docs](https://core.telegram.org/bots/api#inputmedia) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-photo",
6
6
  name: "Send a Photo",
7
7
  description: "Sends a photo to your Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#sendphoto) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-send-sticker",
5
5
  name: "Send a Sticker",
6
6
  description: "Sends a .webp sticker to you Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#sendsticker) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-send-text-message-or-reply",
5
5
  name: "Send a Text Message or Reply",
6
6
  description: "Sends a text message or a reply to your Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#sendmessage) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-video",
6
6
  name: "Send a Video",
7
7
  description: "Sends a video file to your Telegram Desktop application. [See the docs](https://core.telegram.org/bots/api#sendvideo) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-video-note",
6
6
  name: "Send a Video Note",
7
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",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -1,11 +1,11 @@
1
1
  import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
- import contentTypes from "../../content-types.mjs";
2
+ import contentTypes from "../../common/content-types.mjs";
3
3
 
4
4
  export default {
5
5
  key: "telegram_bot_api-send-voice-message",
6
6
  name: "Send a Voice Message",
7
7
  description: "Sends a voice message. [See the docs](https://core.telegram.org/bots/api#sendvoice) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  telegramBotApi,
@@ -0,0 +1,88 @@
1
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
+
3
+ export default {
4
+ key: "telegram_bot_api-set-chat-permissions",
5
+ name: "Set Chat Permissions",
6
+ description: "Set default chat permissions for all members. [See the docs](https://core.telegram.org/bots/api#setchatpermissions) for more information",
7
+ version: "0.0.2",
8
+ type: "action",
9
+ props: {
10
+ telegramBotApi,
11
+ chatId: {
12
+ propDefinition: [
13
+ telegramBotApi,
14
+ "chatId",
15
+ ],
16
+ },
17
+ canSendMessages: {
18
+ type: "boolean",
19
+ label: "Send text messages",
20
+ description: "If the user is allowed to send text messages, contacts, locations and venues",
21
+ optional: true,
22
+ },
23
+ canSendMediaMessages: {
24
+ type: "boolean",
25
+ label: "Send media messages",
26
+ description: "If the user is allowed to send audios, documents, photos, videos, video notes and voice notes",
27
+ optional: true,
28
+ },
29
+ canSendPolls: {
30
+ type: "boolean",
31
+ label: "Send polls",
32
+ description: "If the user is allowed to send polls",
33
+ optional: true,
34
+ },
35
+ canSendOtherMessages: {
36
+ type: "boolean",
37
+ label: "Send other messages",
38
+ description: "If the user is allowed to send animations, games, stickers and use inline bots",
39
+ optional: true,
40
+ },
41
+ canAddWebPagePreviews: {
42
+ type: "boolean",
43
+ label: "Add web page previews",
44
+ description: "If the user is allowed to add web page previews to their messages",
45
+ optional: true,
46
+ },
47
+ canChangeInfo: {
48
+ type: "boolean",
49
+ label: "Change info",
50
+ description: "If the user is allowed to change the chat title, photo and other settings. Ignored in public SuperGroups",
51
+ optional: true,
52
+ },
53
+ canInviteUsers: {
54
+ type: "boolean",
55
+ label: "Send invite users",
56
+ description: "If the user is allowed to invite new users to the chat",
57
+ optional: true,
58
+ },
59
+ canPinMessages: {
60
+ type: "boolean",
61
+ label: "Pin messages",
62
+ description: "If the user is allowed to pin messages. Ignored in public SuperGroups",
63
+ optional: true,
64
+ },
65
+ },
66
+ methods: {
67
+ setPermission(chatPermissions, prop, value) {
68
+ if (value !== null && value !== undefined) {
69
+ chatPermissions[prop] = value;
70
+ }
71
+ return chatPermissions;
72
+ },
73
+ },
74
+ async run({ $ }) {
75
+ let chatPermissions = {};
76
+ chatPermissions = this.setPermission(chatPermissions, "can_send_messages", this.canSendMessages);
77
+ chatPermissions = this.setPermission(chatPermissions, "can_send_media_messages", this.canSendMediaMessages);
78
+ chatPermissions = this.setPermission(chatPermissions, "can_send_polls", this.canSendPolls);
79
+ chatPermissions = this.setPermission(chatPermissions, "can_send_other_messages", this.canSendOtherMessages);
80
+ chatPermissions = this.setPermission(chatPermissions, "can_add_web_page_previews", this.canAddWebPagePreviews);
81
+ chatPermissions = this.setPermission(chatPermissions, "can_change_info", this.canChangeInfo);
82
+ chatPermissions = this.setPermission(chatPermissions, "can_invite_users", this.canInviteUsers);
83
+ chatPermissions = this.setPermission(chatPermissions, "can_pin_messages", this.canPinMessages);
84
+ const resp = await this.telegramBotApi.setChatPermissions(this.chatId, chatPermissions);
85
+ $.export("$summary", `Successfully set chat permissions, "${this.chatId}"`);
86
+ return resp;
87
+ },
88
+ };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "telegram_bot_api-unpin-message",
5
5
  name: "Unpin a Message",
6
6
  description: "Unpins a message. [See the docs](https://core.telegram.org/bots/api#unpinchatmessage) for more information",
7
- version: "0.0.1",
7
+ version: "0.0.2",
8
8
  type: "action",
9
9
  props: {
10
10
  telegramBotApi,
File without changes
File without changes
File without changes
@@ -47,4 +47,16 @@ export default [
47
47
  label: "Poll Answer",
48
48
  value: "poll_answer",
49
49
  },
50
+ {
51
+ label: "My Chat Member",
52
+ value: "my_chat_member",
53
+ },
54
+ {
55
+ label: "Chat Member",
56
+ value: "chat_member",
57
+ },
58
+ {
59
+ label: "Chat Join Request",
60
+ value: "chat_join_request",
61
+ },
50
62
  ];
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/telegram_bot_api",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Pipedream Telegram_bot_api Components",
5
5
  "main": "telegram_bot_api.app.mjs",
6
6
  "keywords": [
@@ -12,7 +12,8 @@
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
14
  "@pipedream/platform": "^0.9.0",
15
- "node-telegram-bot-api": "^0.54.0"
15
+ "node-telegram-bot-api": "^0.54.0",
16
+ "uuid": "^8.3.2"
16
17
  },
17
18
  "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
18
19
  "publishConfig": {
@@ -1,50 +1,36 @@
1
- // eslint-disable-next-line camelcase
2
- import telegramBotApi from "../../telegram_bot_api.app.mjs";
1
+ import base from "../common/webhooks.mjs";
3
2
 
4
3
  export default {
5
- type: "source",
4
+ ...base,
6
5
  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",
6
+ name: "New Channel Updates (Instant)",
7
+ description: "Emit new event each time a channel post is created or updated.",
8
+ version: "0.1.1",
9
+ type: "source",
10
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, [
11
+ methods: {
12
+ ...base.methods,
13
+ getEventTypes() {
14
+ return [
23
15
  "channel_post",
24
16
  "edited_channel_post",
25
- ]);
26
- },
27
- async deactivate() {
28
- await this.telegramBotApi.deleteHook();
17
+ ];
29
18
  },
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,
19
+ getMeta(event, channelPost) {
20
+ return {
21
+ id: event.update_id,
46
22
  summary: `${channelPost.chat.title} - ${channelPost.text}`,
47
- ts: Date.now(),
48
- });
23
+ ts: new Date(channelPost.edit_date ?? channelPost.date),
24
+ };
25
+ },
26
+ processEvent(event) {
27
+ const channelPost = event.edited_channel_post ?? event.channel_post;
28
+
29
+ if (!channelPost?.chat) {
30
+ throw new Error(`Expected event to contain a chat, but received: ${JSON.stringify(event)}`);
31
+ }
32
+
33
+ this.$emit(event, this.getMeta(event, channelPost));
34
+ },
49
35
  },
50
36
  };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ DEPLOY_OFFSET: -25,
3
+ };
@@ -0,0 +1,79 @@
1
+ import telegramBotApi from "../../telegram_bot_api.app.mjs";
2
+ import constants from "./constants.mjs";
3
+ import { v4 as uuid } from "uuid";
4
+
5
+ export default {
6
+ props: {
7
+ telegramBotApi,
8
+ db: "$.service.db",
9
+ http: {
10
+ label: "HTTP Responder",
11
+ description: "Exposes a `respond()` method that lets the source issue HTTP responses",
12
+ type: "$.interface.http",
13
+ customResponse: true,
14
+ },
15
+ },
16
+ hooks: {
17
+ async deploy() {
18
+ /**
19
+ * From the docs: https://core.telegram.org/bots/api#getting-updates
20
+ *
21
+ * Incoming updates are stored on the server until the bot receives them either way,
22
+ * but they will not be kept longer than 24 hours.
23
+ *
24
+ * So there's a big change that no historical event is emitted.
25
+ */
26
+ console.log("Fetching most recent events...");
27
+ const events = await this.telegramBotApi.getUpdates({
28
+ offset: constants.DEPLOY_OFFSET,
29
+ allowed_updates: this.getEventTypes(),
30
+ });
31
+ console.log(`Received ${events.length} event(s)`);
32
+ for (const event of events) {
33
+ this.processEvent(event);
34
+ }
35
+ },
36
+ async activate() {
37
+ const secret = uuid();
38
+ this.setSecret(secret);
39
+ await this.telegramBotApi.createHook(this.http.endpoint, this.getEventTypes(), secret);
40
+ },
41
+ async deactivate() {
42
+ await this.telegramBotApi.deleteHook();
43
+ },
44
+ },
45
+ methods: {
46
+ getSecret() {
47
+ return this.db.get("secret");
48
+ },
49
+ setSecret(secret) {
50
+ this.db.set("secret", secret);
51
+ },
52
+ getEventTypes() {
53
+ throw new Error("getEventTypes is not implemented");
54
+ },
55
+ processEvent() {
56
+ throw new Error("processEvent is not implemented");
57
+ },
58
+ },
59
+ async run(event) {
60
+ // check if event has the same secret
61
+ if (event.headers["x-telegram-bot-api-secret-token"] !== this.getSecret()) {
62
+ console.log("Could not identify sender identity, exiting...");
63
+ return;
64
+ }
65
+
66
+ this.http.respond({
67
+ status: 200,
68
+ });
69
+
70
+ const { body } = event;
71
+
72
+ if (!body) {
73
+ console.log("No body received, exiting...");
74
+ return;
75
+ }
76
+
77
+ this.processEvent(body);
78
+ },
79
+ };
@@ -1,50 +1,31 @@
1
- // eslint-disable-next-line camelcase
2
- import telegramBotApi from "../../telegram_bot_api.app.mjs";
1
+ import base from "../common/webhooks.mjs";
3
2
 
4
3
  export default {
5
- type: "source",
4
+ ...base,
6
5
  key: "telegram_bot_api-message-updates",
7
- name: "Message Updates (Instant)",
6
+ name: "New Message Updates (Instant)",
8
7
  description: "Emit new event each time a Telegram message is created or updated.",
9
- version: "0.0.3",
8
+ version: "0.1.1",
9
+ type: "source",
10
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,
11
+ methods: {
12
+ ...base.methods,
13
+ getMeta(event, message) {
14
+ return {
15
+ id: event.update_id,
16
+ summary: message.text,
17
+ ts: new Date(message.edit_date ?? message.date),
18
+ };
17
19
  },
18
- telegramBotApi,
19
- },
20
- hooks: {
21
- async activate() {
22
- await this.telegramBotApi.createHook(this.http.endpoint, [
20
+ getEventTypes() {
21
+ return [
23
22
  "message",
24
23
  "edited_message",
25
- ]);
24
+ ];
26
25
  },
27
- async deactivate() {
28
- await this.telegramBotApi.deleteHook();
26
+ processEvent(event) {
27
+ const message = event.edited_message ?? event.message;
28
+ this.$emit(event, this.getMeta(event, message));
29
29
  },
30
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
31
  };
@@ -1,63 +1,44 @@
1
- // eslint-disable-next-line camelcase
2
- import telegramBotApi from "../../telegram_bot_api.app.mjs";
1
+ import base from "../common/webhooks.mjs";
3
2
 
4
3
  export default {
4
+ ...base,
5
5
  key: "telegram_bot_api-new-updates",
6
6
  name: "New Updates (Instant)",
7
7
  description: "Emit new event for each new Telegram event.",
8
- version: "0.0.3",
8
+ version: "0.1.1",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
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,
12
+ ...base.props,
21
13
  updateTypes: {
22
14
  propDefinition: [
23
- telegramBotApi, // eslint-disable-line camelcase
15
+ base.props.telegramBotApi,
24
16
  "updateTypes",
25
17
  ],
26
18
  },
27
19
  },
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
20
  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}`;
21
+ ...base.methods,
22
+ getMeta(event) {
23
+ const {
24
+ update_id: id,
25
+ ...eventDetails
26
+ } = event;
27
+ const eventType = Object.keys(eventDetails).pop();
28
+ const summary = `New ${eventType} update: ${id}`;
29
+ const ts = eventDetails[eventType].edit_date ?? eventDetails[eventType].date;
30
+
43
31
  return {
44
- id: body.update_id,
32
+ id,
45
33
  summary,
46
- ts: Date.now(),
34
+ ts,
47
35
  };
48
36
  },
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));
37
+ getEventTypes() {
38
+ return this.updateTypes;
39
+ },
40
+ processEvent(event) {
41
+ this.$emit(event, this.getMeta(event));
42
+ },
62
43
  },
63
44
  };
@@ -1,4 +1,4 @@
1
- import "./env.mjs";
1
+ import "./common/env.mjs";
2
2
  import TelegramBot from "node-telegram-bot-api";
3
3
  import { axios } from "@pipedream/platform";
4
4
  import {
@@ -10,9 +10,9 @@ import {
10
10
  TELEGRAM_BOT_API_UI_MEDIA_STICKER,
11
11
  TELEGRAM_BOT_API_UI_MEDIA_VOICE,
12
12
  TELEGRAM_BOT_API_FORMATTING_MODES,
13
- } from "./constants.mjs";
14
- import updateTypes from "./update-types.mjs";
15
- import { toSingleLineString } from "./utils.mjs";
13
+ } from "./common/constants.mjs";
14
+ import updateTypes from "./common/update-types.mjs";
15
+ import { toSingleLineString } from "./common/utils.mjs";
16
16
 
17
17
  export default {
18
18
  type: "app",
@@ -273,14 +273,15 @@ export default {
273
273
  polling: false,
274
274
  });
275
275
  },
276
- async createHook(url, allowedUpdates) {
276
+ async createHook(url, allowedUpdates, secret) {
277
277
  const config = {
278
278
  method: "POST",
279
279
  url: `${this._getBaseUrl()}/setWebhook`,
280
280
  headers: this._getHeaders(),
281
281
  data: {
282
- url: `${url}/${this.$auth.token}`,
282
+ url,
283
283
  allowed_updates: allowedUpdates,
284
+ secret_token: secret,
284
285
  },
285
286
  };
286
287
  return axios(this, config);
@@ -408,6 +409,22 @@ export default {
408
409
  message_id: messageId,
409
410
  });
410
411
  },
412
+ /**
413
+ * Use this method to set default chat permissions for all members.
414
+ * The bot must be an administrator in the group or a supergroup for this
415
+ * to work and must have the can_restrict_members administrator rights.
416
+ * Returns True on success.
417
+ *
418
+ * @param {Number|String} chatId - Unique identifier for the message
419
+ * recipient
420
+ * @param {TelegramBot.ChatPermissions} [chatPermissions] -
421
+ * A JSON-serialized object for new default chat permissions
422
+ * [the API docs](https://core.telegram.org/bots/api#setchatpermissions)
423
+ * @return `True` on success
424
+ */
425
+ async setChatPermissions(chatId, chatPermissions) {
426
+ return this.sdk().setChatPermissions(chatId, chatPermissions);
427
+ },
411
428
  /**
412
429
  * Send a file (Document/Image, Photo, Audio, Video, Video Note, Voice,
413
430
  * Sticker)