teh-bot 1.0.1 → 1.0.2

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 (2) hide show
  1. package/index.js +26 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -595,8 +595,25 @@ class TelegramBot extends EventEmitter {
595
595
 
596
596
  _createContext(update) {
597
597
  const message = update.message || update.edited_message || update.channel_post || update.callback_query?.message
598
- const chat = message?.chat || update.my_chat_member?.chat || update.chat_member?.chat
599
- const from = message?.from || update.callback_query?.from || update.inline_query?.from
598
+
599
+ // Fallback logic for chat extraction from various update types
600
+ let chat =
601
+ message?.chat || update.my_chat_member?.chat || update.chat_member?.chat || update.chat_join_request?.chat
602
+
603
+ // Explicit extraction for callback_query which might not have a message (inline buttons)
604
+ if (!chat && update.callback_query) {
605
+ chat = update.callback_query.message?.chat
606
+ }
607
+
608
+ const from =
609
+ message?.from ||
610
+ update.callback_query?.from ||
611
+ update.inline_query?.from ||
612
+ update.chosen_inline_result?.from ||
613
+ update.shipping_query?.from ||
614
+ update.pre_checkout_query?.from ||
615
+ update.poll_answer?.user ||
616
+ update.my_chat_member?.from
600
617
 
601
618
  const ctx = {
602
619
  update,
@@ -615,17 +632,20 @@ class TelegramBot extends EventEmitter {
615
632
 
616
633
  // Baileys-style simplified response
617
634
  ctx.send = (content, opts) => {
618
- if (!ctx.chat?.id) {
635
+ const chatId = ctx.chat?.id || update.callback_query?.from?.id || update.inline_query?.from?.id
636
+ if (!chatId) {
637
+ console.error("[v0] Context update without chat_id:", JSON.stringify(update))
619
638
  throw new Error("[Teh] Cannot send message: chat_id is not available in this context")
620
639
  }
621
- return this.sendMessage(ctx.chat.id, content, opts)
640
+ return this.sendMessage(chatId, content, opts)
622
641
  }
623
642
 
624
643
  ctx.reply = (text, opts) => {
625
- if (!ctx.chat?.id) {
644
+ const chatId = ctx.chat?.id || update.callback_query?.from?.id
645
+ if (!chatId) {
626
646
  throw new Error("[Teh] Cannot reply: chat_id is not available in this context")
627
647
  }
628
- return this.sendMessage(ctx.chat.id, text, {
648
+ return this.sendMessage(chatId, text, {
629
649
  reply_to_message_id: ctx.message?.message_id,
630
650
  ...opts,
631
651
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teh-bot",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Lightweight, high-performance Telegram Bot API module with zero dependencies",
5
5
  "keywords": [
6
6
  "telegram",