@codebam/cf-workers-telegram-bot 8.1.0 → 8.1.1

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.
@@ -26,6 +26,9 @@ export default class TelegramApi {
26
26
  * @param token - bot token
27
27
  */
28
28
  async getFile(botApi, data, token) {
29
+ if (data.file_id === '') {
30
+ return new Response();
31
+ }
29
32
  const url = this.getApiUrl(botApi, 'getFile', data);
30
33
  const response = await fetch(url);
31
34
  const json = await response.json();
@@ -35,7 +35,17 @@ export default class TelegramExecutionContext {
35
35
  * @param options - any additional options to pass to sendPhoto
36
36
  */
37
37
  replyPhoto(photo: string, caption?: string, options?: Record<string, number | string | boolean>): Promise<Response | undefined>;
38
+ /**
39
+ * Send typing in a chat
40
+ */
38
41
  sendTyping(): Promise<Response | undefined>;
42
+ /**
43
+ * Reply to an inline message with a title and content
44
+ * @param title - title to reply with
45
+ * @param message - message contents to reply with
46
+ * @param parse_mode - parse mode to use
47
+ */
48
+ replyInline(title: string, message: string, parse_mode?: string): Promise<Response | undefined>;
39
49
  /**
40
50
  * Reply to the last message with text
41
51
  * @param message - text to reply with
@@ -35,7 +35,7 @@ export default class TelegramExecutionContext {
35
35
  else if (this.update.callback_query?.id) {
36
36
  this.update_type = 'callback';
37
37
  }
38
- else if (this.update.business_message?.text) {
38
+ else if (this.update.business_message) {
39
39
  this.update_type = 'business_message';
40
40
  }
41
41
  }
@@ -103,6 +103,9 @@ export default class TelegramExecutionContext {
103
103
  break;
104
104
  }
105
105
  }
106
+ /**
107
+ * Send typing in a chat
108
+ */
106
109
  async sendTyping() {
107
110
  switch (this.update_type) {
108
111
  case 'message':
@@ -120,6 +123,23 @@ export default class TelegramExecutionContext {
120
123
  break;
121
124
  }
122
125
  }
126
+ /**
127
+ * Reply to an inline message with a title and content
128
+ * @param title - title to reply with
129
+ * @param message - message contents to reply with
130
+ * @param parse_mode - parse mode to use
131
+ */
132
+ async replyInline(title, message, parse_mode = '') {
133
+ switch (this.update_type) {
134
+ case 'inline':
135
+ return await this.api.answerInline(this.bot.api.toString(), {
136
+ inline_query_id: this.update.inline_query?.id.toString() ?? '',
137
+ results: [new TelegramInlineQueryResultArticle({ content: message, title, parse_mode })],
138
+ });
139
+ default:
140
+ break;
141
+ }
142
+ }
123
143
  /**
124
144
  * Reply to the last message with text
125
145
  * @param message - text to reply with
@@ -154,7 +174,7 @@ export default class TelegramExecutionContext {
154
174
  case 'inline':
155
175
  return await this.api.answerInline(this.bot.api.toString(), {
156
176
  inline_query_id: this.update.inline_query?.id.toString() ?? '',
157
- results: [new TelegramInlineQueryResultArticle(message)],
177
+ results: [new TelegramInlineQueryResultArticle({ title: message, content: message, parse_mode })],
158
178
  });
159
179
  case 'document':
160
180
  return await this.api.sendMessage(this.bot.api.toString(), {
@@ -4,5 +4,10 @@ export default class TelegramInlineQueryResultArticle extends TelegramInlineQuer
4
4
  title: string;
5
5
  input_message_content: TelegramInputMessageContent;
6
6
  thumb_url: string;
7
- constructor(content: string, title?: string, parse_mode?: string, thumb_url?: string);
7
+ constructor(data: {
8
+ content: string;
9
+ title?: string;
10
+ parse_mode?: string;
11
+ thumb_url?: string;
12
+ });
8
13
  }
@@ -3,13 +3,13 @@ export default class TelegramInlineQueryResultArticle extends TelegramInlineQuer
3
3
  title;
4
4
  input_message_content;
5
5
  thumb_url;
6
- constructor(content, title = content, parse_mode = '', thumb_url = '') {
6
+ constructor(data) {
7
7
  super('article');
8
- this.title = title;
8
+ this.title = data.title ?? '';
9
9
  this.input_message_content = {
10
- message_text: content.toString(),
11
- parse_mode,
10
+ message_text: data.content.toString(),
11
+ parse_mode: data.parse_mode ?? '',
12
12
  };
13
- this.thumb_url = thumb_url;
13
+ this.thumb_url = data.thumb_url ?? '';
14
14
  }
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "8.1.0",
3
+ "version": "8.1.1",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",
@@ -31,16 +31,16 @@
31
31
  "url": "https://github.com/codebam/cf-workers-telegram-bot.git"
32
32
  },
33
33
  "devDependencies": {
34
- "@cloudflare/workers-types": "^4.20241127.0",
35
- "@eslint/js": "^9.15.0",
36
- "@typescript-eslint/eslint-plugin": "^8.16.0",
37
- "@typescript-eslint/parser": "^8.16.0",
38
- "eslint": "^9.15.0",
34
+ "@cloudflare/workers-types": "^4.20241202.0",
35
+ "@eslint/js": "^9.16.0",
36
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
37
+ "@typescript-eslint/parser": "^8.17.0",
38
+ "eslint": "^9.16.0",
39
39
  "eslint-config-prettier": "^9.1.0",
40
- "globals": "^15.12.0",
41
- "prettier": "^3.4.1",
40
+ "globals": "^15.13.0",
41
+ "prettier": "^3.4.2",
42
42
  "typescript": "^5.7.2",
43
- "typescript-eslint": "^8.16.0",
44
- "vitest": "^2.1.6"
43
+ "typescript-eslint": "^8.17.0",
44
+ "vitest": "^2.1.8"
45
45
  }
46
46
  }