@codebam/cf-workers-telegram-bot 6.2.0 → 6.4.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.
@@ -0,0 +1,5 @@
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import TelegramBot from '../telegram_bot';
3
+ import { TelegramUpdate } from '../types';
4
+ declare const _default: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
5
+ export default _default;
@@ -0,0 +1,8 @@
1
+ export default async (self, update) => {
2
+ const chat_id = update.message?.reply_to_message?.chat.id;
3
+ const user_id = update.message?.reply_to_message?.from.id;
4
+ if (chat_id && user_id) {
5
+ return self.banChatMember(chat_id, user_id, 0, true);
6
+ }
7
+ return new Response('ok');
8
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import TelegramBot from '../telegram_bot';
3
+ import { TelegramUpdate } from '../types';
4
+ declare const _default: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
5
+ export default _default;
@@ -0,0 +1,8 @@
1
+ export default async (self, update) => {
2
+ const chat_id = update.message?.reply_to_message?.chat.id;
3
+ const user_id = update.message?.reply_to_message?.from.id;
4
+ if (chat_id && user_id) {
5
+ return self.restrictChatMember(chat_id, user_id, { can_send_messages: false }, false, 0);
6
+ }
7
+ return new Response('ok');
8
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="@cloudflare/workers-types" />
2
+ import TelegramBot from '../telegram_bot';
3
+ import { TelegramUpdate } from '../types';
4
+ declare const _default: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
5
+ export default _default;
@@ -0,0 +1 @@
1
+ export default async (self, update) => self.sendMessage(update.message?.chat.id ?? 0, `Hello, send me a message to start chatting with ${self.chat_model}`);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
  import BotApi from './bot_api';
3
- import { Commands, TelegramInlineQueryResult, TelegramUpdate, Webhook, Update } from './types';
3
+ import { Commands, TelegramInlineQueryResult, TelegramUpdate, Webhook, Update, ChatPermissions } from './types';
4
4
  import Handler from './handler';
5
5
  export default class TelegramApi extends BotApi {
6
6
  constructor(commands: Commands, webhook: Webhook, handler: Handler);
@@ -29,4 +29,6 @@ export default class TelegramApi extends BotApi {
29
29
  sendPoll: (chat_id: number, question: string, options: string[], is_anonymous?: boolean, type?: string, allows_multiple_answers?: boolean, correct_option_id?: number, explanation?: string, explanation_parse_mode?: string, open_period?: number, close_date?: number, is_closed?: boolean, disable_notification?: boolean, reply_to_message_id?: number) => Promise<Response>;
30
30
  sendDice: (chat_id: number, emoji?: string, disable_notification?: boolean, reply_to_message_id?: number) => Promise<Response>;
31
31
  getUserProfilePhotos: (user_id: number, offset?: number, limit?: number) => Promise<Response>;
32
+ banChatMember: (chat_id: number | string, user_id: number, until_date?: number, revoke_messages?: boolean) => Promise<Response>;
33
+ restrictChatMember: (chat_id: number | string, user_id: number, permissions: ChatPermissions, use_independent_chat_permissions: boolean, until_date: number) => Promise<Response>;
32
34
  }
@@ -170,4 +170,17 @@ export default class TelegramApi extends BotApi {
170
170
  offset: offset.toString(),
171
171
  limit: limit.toString(),
172
172
  }).href));
173
+ banChatMember = async (chat_id, user_id, until_date = 0, revoke_messages = false) => fetch(log(addSearchParams(new URL(`${this.webhook.api.origin}${this.webhook.api.pathname}/banChatMember`), {
174
+ chat_id: chat_id.toString(),
175
+ user_id: user_id.toString(),
176
+ until_date: until_date.toString(),
177
+ revoke_messages: revoke_messages.toString(),
178
+ }).href));
179
+ restrictChatMember = async (chat_id, user_id, permissions, use_independent_chat_permissions, until_date) => fetch(log(addSearchParams(new URL(`${this.webhook.api.origin}${this.webhook.api.pathname}/restrictChatMember`), {
180
+ chat_id: chat_id.toString(),
181
+ user_id: user_id.toString(),
182
+ permissions: JSON.stringify(permissions),
183
+ use_independent_chat_permissions: use_independent_chat_permissions.toString(),
184
+ until_date: until_date.toString(),
185
+ }).href));
173
186
  }
@@ -19,6 +19,9 @@ export default class TelegramBot extends TelegramApi {
19
19
  toss: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
20
20
  ping: (self: TelegramBot, update: TelegramUpdate, args: string[]) => Promise<Response>;
21
21
  getChatInfo: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
22
+ start: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
23
+ ban: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
24
+ mute: (self: TelegramBot, update: TelegramUpdate) => Promise<Response>;
22
25
  url: URL;
23
26
  kv: Kv;
24
27
  get_set: KVNamespace;
@@ -16,6 +16,9 @@ import commandlist from './commands/commandlist';
16
16
  import toss from './commands/toss';
17
17
  import ping from './commands/ping';
18
18
  import getchatinfo from './commands/getchatinfo';
19
+ import start from './commands/start';
20
+ import ban from './commands/ban';
21
+ import mute from './commands/mute';
19
22
  export default class TelegramBot extends TelegramApi {
20
23
  translate;
21
24
  clear;
@@ -34,6 +37,9 @@ export default class TelegramBot extends TelegramApi {
34
37
  toss;
35
38
  ping;
36
39
  getChatInfo;
40
+ start;
41
+ ban;
42
+ mute;
37
43
  url;
38
44
  kv;
39
45
  get_set;
@@ -61,6 +67,9 @@ export default class TelegramBot extends TelegramApi {
61
67
  this.toss = toss;
62
68
  this.ping = ping;
63
69
  this.getChatInfo = getchatinfo;
70
+ this.start = start;
71
+ this.ban = ban;
72
+ this.mute = mute;
64
73
  this.url = config.url;
65
74
  this.kv = config.kv;
66
75
  this.get_set = config.kv?.get_set;
@@ -16,4 +16,7 @@ export default class TelegramCommands {
16
16
  static commandList: TelegramCommand;
17
17
  static image: TelegramCommand;
18
18
  static translate: TelegramCommand;
19
+ static start: TelegramCommand;
20
+ static ban: TelegramCommand;
21
+ static mute: TelegramCommand;
19
22
  }
@@ -15,4 +15,7 @@ export default class TelegramCommands {
15
15
  static commandList = async (bot, update) => bot.commandList(bot, update);
16
16
  static image = async (bot, update, args) => bot.image(bot, update, args);
17
17
  static translate = async (bot, update, args) => bot.translate(bot, update, args);
18
+ static start = async (bot, update) => bot.start(bot, update);
19
+ static ban = async (bot, update) => bot.ban(bot, update);
20
+ static mute = async (bot, update) => bot.mute(bot, update);
18
21
  }
@@ -0,0 +1,17 @@
1
+ type ChatPermissions = {
2
+ can_send_messages?: boolean;
3
+ can_send_audios?: boolean;
4
+ can_send_documents?: boolean;
5
+ can_send_photos?: boolean;
6
+ can_send_videos?: boolean;
7
+ can_send_video_notes?: boolean;
8
+ can_send_voice_notes?: boolean;
9
+ can_send_polls?: boolean;
10
+ can_send_other_messages?: boolean;
11
+ can_add_web_page_previews?: boolean;
12
+ can_change_info?: boolean;
13
+ can_invite_users?: boolean;
14
+ can_pin_messages?: boolean;
15
+ can_manage_topics?: boolean;
16
+ };
17
+ export default ChatPermissions;
@@ -0,0 +1 @@
1
+ export {};
@@ -25,4 +25,5 @@ import TelegramInlineQueryResult from './types/TelegramInlineQueryResult';
25
25
  import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto';
26
26
  import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle';
27
27
  import DDGQueryResponse from './types/DDGQueryResponse';
28
- export { Webhook, Command, TelegramCommand, Commands, Kv, Config, localhost, WebhookCommands, Joke, Bored, Balance, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramInputMessageContent, TelegramInlineQuery, Update, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, DDGQueryResponse, };
28
+ import ChatPermissions from './types/ChatPermissions';
29
+ export { Webhook, Command, TelegramCommand, Commands, Kv, Config, localhost, WebhookCommands, Joke, Bored, Balance, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramInputMessageContent, TelegramInlineQuery, Update, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, DDGQueryResponse, ChatPermissions, };
@@ -23,7 +23,9 @@ export default {
23
23
  '/clear': TelegramCommands.clear,
24
24
  '/help': TelegramCommands.commandList,
25
25
  '/image': TelegramCommands.image,
26
- '/start': TelegramCommands.question,
26
+ '/start': TelegramCommands.start,
27
+ '/ban': TelegramCommands.ban,
28
+ '/mute': TelegramCommands.mute,
27
29
  },
28
30
  kv: { get_set: env.KV_GET_SET, uid_data: env.KV_UID_DATA },
29
31
  ai: env.AI,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "6.2.0",
3
+ "version": "6.4.0",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main/src/main.js",
6
6
  "module": "./dist/main/src/main.js",
@@ -41,5 +41,5 @@
41
41
  "typescript": "^5.4.5",
42
42
  "typescript-eslint": "^7.8.0"
43
43
  },
44
- "gitHead": "cf3c23508164f91e2050ff87c59053ca86548f9b"
44
+ "gitHead": "3908a7cd0ca117b7e641960bb8a20cadaddc307e"
45
45
  }