telegram-support-bot 0.1.12 → 0.1.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f542e3e9a21dc2d7d9c45c9b65b19aec360bad95b60f0e4f999f3a9f4c532700
4
- data.tar.gz: 0136afb1b7bea4ce86afcd4f28b3af38f56743f4a2a4a87c29bfd33287f792e4
3
+ metadata.gz: 0e2776425f88d7b3255ed8130fbc382325c5c50234963b4cc4d626092e16defd
4
+ data.tar.gz: 7529852a1df10a48cf1b1381fb0d04822a9fc70875340e0cae3afb36da0430d2
5
5
  SHA512:
6
- metadata.gz: 7599da9dab831b489bd6f687bf9d779fc5b3582a1a5546eea8d3c00e4febce46bddccc6aaa118177ad20e296f95fb1ff8f8bc54f013e30e41e462c9e3f8aa576
7
- data.tar.gz: 00f33f8a9eed3902cbde9584d06a781880f6efe9a0cbd6f1405ac2450e82da1e0605a3c0eed25520e9c6c46e8291e40495276cd08cc59a0e92c7494023c35a13
6
+ metadata.gz: cc195cf56e0bdd9299d65342ab7619d9bc091727a09c66f3d4e56a4dde5689b3083cf0cc0531ab7784f85bb600b9b097c5ab056f62f617b2a420b47b980f54b5
7
+ data.tar.gz: d931f2c70b662d7167cc670a3e2b8eb6f88cfb8b3036dbdcd2f95f50b5c643762f1309921e0c593ce1b68ce38ff579e648bdbd751ad825074690a82a50705a76
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.1.13] - 2026-02-26
8
+
9
+ ### Added
10
+ - Optional `forward_start_to_support` configuration to forward the first user `/start`
11
+ message to support chat, so the team can proactively start the conversation.
12
+
7
13
  ## [0.1.12] - 2026-02-26
8
14
 
9
15
  ### Fixed
data/README.md CHANGED
@@ -50,6 +50,8 @@ TelegramSupportBot.configure do |config|
50
50
  config.non_command_message_response = 'I only respond to commands. Please use /start.'
51
51
  # Optional: ask users to share their phone once for account lookup.
52
52
  config.request_contact_on_start = true
53
+ # Optional: forward the user's first /start message to support chat.
54
+ config.forward_start_to_support = false
53
55
  # Optional: block forwarding until contact is shared.
54
56
  config.require_contact_for_support = false
55
57
  # Optional callback to persist/lookup user profile in your app.
@@ -222,6 +224,7 @@ Behavior:
222
224
  - Triggered only for user-chat commands that start with `/` and are not `/start`.
223
225
  - Receives `command` (normalized to lowercase), `bot_username` (if present), and `args` (text after command).
224
226
  - Return `true` to stop forwarding to support chat; return `false`/`nil` to keep default forwarding.
227
+ - `/start` can be forwarded once per user to support chat when `forward_start_to_support = true`.
225
228
 
226
229
  ## State Storage (Single Pod vs Multi-Pod)
227
230
 
@@ -6,7 +6,7 @@ module TelegramSupportBot
6
6
  :auto_away_message, :auto_away_interval, :ignore_unknown_commands,
7
7
  :ignore_non_command_messages, :non_command_message_response,
8
8
  :request_contact_on_start, :require_contact_for_support, :contact_request_message,
9
- :contact_received_message, :contact_invalid_message, :on_contact_received,
9
+ :contact_received_message, :contact_invalid_message, :forward_start_to_support, :on_contact_received,
10
10
  :on_user_command,
11
11
  :state_store, :state_store_options, :mapping_ttl_seconds,
12
12
  :reaction_count_ttl_seconds, :user_profile_ttl_seconds
@@ -25,6 +25,7 @@ module TelegramSupportBot
25
25
  @contact_request_message = 'Please share your phone number so we can quickly identify your account.'
26
26
  @contact_received_message = 'Thanks! We have saved your phone number.'
27
27
  @contact_invalid_message = 'Please use the button below to share your own phone number.'
28
+ @forward_start_to_support = false
28
29
  @on_contact_received = nil
29
30
  @on_user_command = nil
30
31
  @state_store = :memory
@@ -11,6 +11,7 @@ module TelegramSupportBot
11
11
  @reverse_message_map = {}
12
12
  @reaction_count_state = {}
13
13
  @user_profiles = {}
14
+ @start_forwarded_users = {}
14
15
  end
15
16
 
16
17
  def message_map
@@ -49,6 +50,15 @@ module TelegramSupportBot
49
50
  )
50
51
  end
51
52
 
53
+ def start_forwarded_users
54
+ @start_forwarded_users_proxy ||= StateStore::MapProxy.new(
55
+ get_proc: ->(key) { get_start_forwarded_user(key) },
56
+ set_proc: ->(key, value) { set_start_forwarded_user(key, value) },
57
+ clear_proc: -> { clear_start_forwarded_users },
58
+ size_proc: -> { start_forwarded_users_size }
59
+ )
60
+ end
61
+
52
62
  def get_message_mapping(key)
53
63
  synchronize { @message_map[normalize_key(key)] }
54
64
  end
@@ -113,6 +123,22 @@ module TelegramSupportBot
113
123
  synchronize { @user_profiles.size }
114
124
  end
115
125
 
126
+ def get_start_forwarded_user(key)
127
+ synchronize { @start_forwarded_users[normalize_key(key)] }
128
+ end
129
+
130
+ def set_start_forwarded_user(key, value)
131
+ synchronize { @start_forwarded_users[normalize_key(key)] = value }
132
+ end
133
+
134
+ def clear_start_forwarded_users
135
+ synchronize { @start_forwarded_users.clear }
136
+ end
137
+
138
+ def start_forwarded_users_size
139
+ synchronize { @start_forwarded_users.size }
140
+ end
141
+
116
142
  private
117
143
 
118
144
  def synchronize(&block)
@@ -57,6 +57,15 @@ module TelegramSupportBot
57
57
  )
58
58
  end
59
59
 
60
+ def start_forwarded_users
61
+ @start_forwarded_users_proxy ||= StateStore::MapProxy.new(
62
+ get_proc: ->(key) { get_start_forwarded_user(key) },
63
+ set_proc: ->(key, value) { set_start_forwarded_user(key, value) },
64
+ clear_proc: -> { clear_start_forwarded_users },
65
+ size_proc: -> { start_forwarded_users_size }
66
+ )
67
+ end
68
+
60
69
  def get_message_mapping(key)
61
70
  payload = parse_json(@redis.get(map_key(:message_map, key)))
62
71
  symbolize_hash(payload)
@@ -124,6 +133,22 @@ module TelegramSupportBot
124
133
  count_by_prefix(prefix(:user_profiles))
125
134
  end
126
135
 
136
+ def get_start_forwarded_user(key)
137
+ parse_json(@redis.get(map_key(:start_forwarded_users, key)))
138
+ end
139
+
140
+ def set_start_forwarded_user(key, value)
141
+ write_json(map_key(:start_forwarded_users, key), value, @user_profile_ttl_seconds)
142
+ end
143
+
144
+ def clear_start_forwarded_users
145
+ delete_by_prefix(prefix(:start_forwarded_users))
146
+ end
147
+
148
+ def start_forwarded_users_size
149
+ count_by_prefix(prefix(:start_forwarded_users))
150
+ end
151
+
127
152
  private
128
153
 
129
154
  def prefix(name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TelegramSupportBot
4
- VERSION = "0.1.12"
4
+ VERSION = "0.1.13"
5
5
  end
@@ -59,6 +59,10 @@ module TelegramSupportBot
59
59
  state_store(bot_key).user_profiles
60
60
  end
61
61
 
62
+ def start_forwarded_users(bot_key = nil)
63
+ state_store(bot_key).start_forwarded_users
64
+ end
65
+
62
66
  def user_profile(chat_id, bot: nil)
63
67
  profiles = user_profiles(bot)
64
68
  profiles[chat_id] || profiles[chat_id.to_s] || profiles[chat_id.to_i]
@@ -178,6 +182,7 @@ module TelegramSupportBot
178
182
  if command_data && command_data[:command] == '/start'
179
183
  adapter.send_message(chat_id: chat_id, text: configuration.welcome_message)
180
184
  request_contact_from_user(chat_id: chat_id) if should_request_contact?(chat_id)
185
+ forward_start_to_support_chat_if_needed(message, chat_id: chat_id)
181
186
  return
182
187
  end
183
188
 
@@ -363,6 +368,7 @@ module TelegramSupportBot
363
368
  end
364
369
  end
365
370
  # scheduler.schedule_auto_away_message(message_id, message_chat_id)
371
+ result
366
372
  end
367
373
 
368
374
  def handle_my_chat_member_update(update)
@@ -503,6 +509,21 @@ module TelegramSupportBot
503
509
  configuration.request_contact_on_start && !contact_known_for_user?(chat_id)
504
510
  end
505
511
 
512
+ def should_forward_start_to_support?(chat_id)
513
+ configuration.forward_start_to_support && !start_forwarded_to_support?(chat_id)
514
+ end
515
+
516
+ def forward_start_to_support_chat_if_needed(message, chat_id:)
517
+ return unless should_forward_start_to_support?(chat_id)
518
+ return unless forward_message_to_support_chat(message, chat_id: chat_id)
519
+
520
+ start_forwarded_users[chat_id] = true
521
+ end
522
+
523
+ def start_forwarded_to_support?(chat_id)
524
+ !start_forwarded_users[chat_id].nil?
525
+ end
526
+
506
527
  def contact_known_for_user?(chat_id)
507
528
  !user_profile(chat_id).nil?
508
529
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-support-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Buslaev