@zero-bot.net/tg-bot-api 1.2.0 → 1.3.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.
package/lib/telegram.js CHANGED
@@ -47,7 +47,9 @@ const _messageTypes = ['text', 'animation', 'audio', 'channel_chat_created', 'co
47
47
  // Bot API 10.2
48
48
  'ephemeral_message_id', 'receiver_user', 'community_chat_added', 'community_chat_removed',
49
49
  // Bot API 10.3
50
- 'stopped_message_generation', 'community_chat_joined'];
50
+ 'stopped_message_generation', 'community_chat_joined',
51
+ // Bot API 8.3+
52
+ 'giveaway_created', 'giveaway', 'giveaway_winners', 'giveaway_completed', 'chat_boost_added', 'story', 'chat_background_set', 'forum_topic_created', 'forum_topic_closed', 'forum_topic_reopened', 'forum_topic_edited', 'general_forum_topic_hidden', 'general_forum_topic_unhidden', 'write_access_allowed', 'boost'];
51
53
 
52
54
  const _deprecatedMessageTypes = ['new_chat_participant', 'left_chat_participant'];
53
55
 
@@ -816,6 +818,34 @@ class TelegramBot extends EventEmitter {
816
818
  debug('Process Update removed_chat_boost %j', removedChatBoost);
817
819
  this.emit('removed_chat_boost', removedChatBoost);
818
820
  }
821
+
822
+ // Update-level types not tied to message content
823
+ const purchasedPaidMedia = update.purchased_paid_media;
824
+ const subscription = update.subscription;
825
+ const managedBot = update.managed_bot;
826
+ const guestMessage = update.guest_message;
827
+ const stoppedMessageGeneration = update.stopped_message_generation;
828
+ const reaction = update.reaction;
829
+
830
+ if (purchasedPaidMedia) {
831
+ debug('Process Update purchased_paid_media %j', purchasedPaidMedia);
832
+ this.emit('purchased_paid_media', purchasedPaidMedia);
833
+ } else if (subscription) {
834
+ debug('Process Update subscription %j', subscription);
835
+ this.emit('subscription', subscription);
836
+ } else if (managedBot) {
837
+ debug('Process Update managed_bot %j', managedBot);
838
+ this.emit('managed_bot', managedBot);
839
+ } else if (guestMessage) {
840
+ debug('Process Update guest_message %j', guestMessage);
841
+ this.emit('guest_message', guestMessage);
842
+ } else if (stoppedMessageGeneration) {
843
+ debug('Process Update stopped_message_generation %j', stoppedMessageGeneration);
844
+ this.emit('stopped_message_generation', stoppedMessageGeneration);
845
+ } else if (reaction) {
846
+ debug('Process Update reaction %j', reaction);
847
+ this.emit('reaction', reaction);
848
+ }
819
849
  }
820
850
 
821
851
  /** Start Telegram Bot API methods */
@@ -3206,7 +3236,14 @@ class TelegramBot extends EventEmitter {
3206
3236
  * @see https://core.telegram.org/bots/api#sendgift
3207
3237
  */
3208
3238
  sendGift(userId, giftId, form = {}) {
3209
- form.user_id = userId;
3239
+ if (typeof userId === 'number' || typeof userId === 'string') {
3240
+ // Check if it looks like a chat ID (negative numbers or @channel)
3241
+ if (String(userId).charAt(0) === '-' || String(userId).charAt(0) === '@') {
3242
+ form.chat_id = userId;
3243
+ } else {
3244
+ form.user_id = userId;
3245
+ }
3246
+ }
3210
3247
  form.gift_id = giftId;
3211
3248
  return this._request('sendGift', { form });
3212
3249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero-bot.net/tg-bot-api",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Telegram Bot API",
5
5
  "main": "./index.js",
6
6
  "types": "./lib/telegram.d.ts",