teh-bot 1.0.1 → 1.0.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.
- package/index.js +40 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -384,6 +384,11 @@ class TelegramBot extends EventEmitter {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
command(cmd, handler) {
|
|
387
|
+
if (handler === undefined) {
|
|
388
|
+
const commandName = typeof cmd === "string" ? (cmd.startsWith("/") ? cmd : `/${cmd}`) : ""
|
|
389
|
+
return this.commands.get(commandName)
|
|
390
|
+
}
|
|
391
|
+
|
|
387
392
|
if (typeof handler !== "function") {
|
|
388
393
|
throw new Error("Command handler must be a function")
|
|
389
394
|
}
|
|
@@ -595,8 +600,26 @@ class TelegramBot extends EventEmitter {
|
|
|
595
600
|
|
|
596
601
|
_createContext(update) {
|
|
597
602
|
const message = update.message || update.edited_message || update.channel_post || update.callback_query?.message
|
|
598
|
-
|
|
599
|
-
|
|
603
|
+
|
|
604
|
+
// Fallback logic for chat extraction from various update types
|
|
605
|
+
const chat =
|
|
606
|
+
update.message?.chat ||
|
|
607
|
+
update.callback_query?.message?.chat ||
|
|
608
|
+
update.my_chat_member?.chat ||
|
|
609
|
+
update.chat_member?.chat ||
|
|
610
|
+
update.chat_join_request?.chat ||
|
|
611
|
+
update.edited_message?.chat ||
|
|
612
|
+
update.channel_post?.chat
|
|
613
|
+
|
|
614
|
+
const from =
|
|
615
|
+
update.message?.from ||
|
|
616
|
+
update.callback_query?.from ||
|
|
617
|
+
update.inline_query?.from ||
|
|
618
|
+
update.chosen_inline_result?.from ||
|
|
619
|
+
update.shipping_query?.from ||
|
|
620
|
+
update.pre_checkout_query?.from ||
|
|
621
|
+
update.poll_answer?.user ||
|
|
622
|
+
update.my_chat_member?.from
|
|
600
623
|
|
|
601
624
|
const ctx = {
|
|
602
625
|
update,
|
|
@@ -615,17 +638,26 @@ class TelegramBot extends EventEmitter {
|
|
|
615
638
|
|
|
616
639
|
// Baileys-style simplified response
|
|
617
640
|
ctx.send = (content, opts) => {
|
|
618
|
-
|
|
619
|
-
|
|
641
|
+
const chatId =
|
|
642
|
+
ctx.chat?.id ||
|
|
643
|
+
update.callback_query?.from?.id ||
|
|
644
|
+
update.inline_query?.from?.id ||
|
|
645
|
+
update.message?.from?.id ||
|
|
646
|
+
from?.id
|
|
647
|
+
|
|
648
|
+
if (!chatId) {
|
|
649
|
+
console.error("[v0] Context update without valid chatId destination:", JSON.stringify(update))
|
|
650
|
+
throw new Error("[Teh] Cannot send message: chat_id could not be resolved from this update context")
|
|
620
651
|
}
|
|
621
|
-
return this.sendMessage(
|
|
652
|
+
return this.sendMessage(chatId, content, opts)
|
|
622
653
|
}
|
|
623
654
|
|
|
624
655
|
ctx.reply = (text, opts) => {
|
|
625
|
-
|
|
626
|
-
|
|
656
|
+
const chatId = ctx.chat?.id || update.callback_query?.from?.id || from?.id
|
|
657
|
+
if (!chatId) {
|
|
658
|
+
throw new Error("[Teh] Cannot reply: chat_id could not be resolved from this update context")
|
|
627
659
|
}
|
|
628
|
-
return this.sendMessage(
|
|
660
|
+
return this.sendMessage(chatId, text, {
|
|
629
661
|
reply_to_message_id: ctx.message?.message_id,
|
|
630
662
|
...opts,
|
|
631
663
|
})
|