@codebam/cf-workers-telegram-bot 11.5.3 → 11.6.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.
- package/dist/telegram_api.js +10 -1
- package/dist/telegram_bot.js +12 -5
- package/package.json +1 -1
package/dist/telegram_api.js
CHANGED
|
@@ -27,7 +27,16 @@ export default class TelegramApi {
|
|
|
27
27
|
async fetchAndLog(url, slug, data) {
|
|
28
28
|
const response = await fetch(url);
|
|
29
29
|
if (response.status !== 200) {
|
|
30
|
-
|
|
30
|
+
const cloned = response.clone();
|
|
31
|
+
let errorDescription = '';
|
|
32
|
+
try {
|
|
33
|
+
const json = (await cloned.json());
|
|
34
|
+
errorDescription = json.description ? `: ${json.description}` : '';
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// ignore
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Telegram API error: ${String(response.status)} ${response.statusText}${errorDescription}`);
|
|
31
40
|
}
|
|
32
41
|
const cloned = response.clone();
|
|
33
42
|
try {
|
package/dist/telegram_bot.js
CHANGED
|
@@ -114,16 +114,23 @@ export default class TelegramBot {
|
|
|
114
114
|
case 'inline':
|
|
115
115
|
return ':inline' in this.commands ? ':inline' : this.defaultCommand;
|
|
116
116
|
case 'guest_message':
|
|
117
|
-
|
|
117
|
+
// For guest messages, we fall through to command detection if it's not a special type
|
|
118
|
+
break;
|
|
118
119
|
case 'pre_checkout_query':
|
|
119
120
|
return ':pre_checkout_query' in this.commands ? ':pre_checkout_query' : this.defaultCommand;
|
|
120
121
|
case 'successful_payment':
|
|
121
122
|
return ':successful_payment' in this.commands ? ':successful_payment' : this.defaultCommand;
|
|
122
123
|
}
|
|
123
|
-
// Then check if
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
// Then check if there's a command starting with / anywhere in the message
|
|
125
|
+
const commandIndex = args.findIndex((arg) => arg.startsWith('/'));
|
|
126
|
+
if (commandIndex !== -1) {
|
|
127
|
+
const fullCommand = args[commandIndex];
|
|
128
|
+
const command = fullCommand.substring(1, fullCommand.lastIndexOf('@') > -1 ? fullCommand.lastIndexOf('@') : fullCommand.length);
|
|
129
|
+
if (command in this.commands) {
|
|
130
|
+
// Shift args so the command handler sees the command at index 0
|
|
131
|
+
ctx.args = args.slice(commandIndex);
|
|
132
|
+
return command;
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
return this.defaultCommand;
|
|
129
136
|
}
|