merve HF Staff commited on
Commit
dcaca40
·
verified ·
1 Parent(s): 164e59e

Prompt user for Telegram id via @userinfobot instead of getUpdates

Browse files
Files changed (1) hide show
  1. bootstrap.sh +10 -21
bootstrap.sh CHANGED
@@ -177,27 +177,16 @@ else
177
  [ -n "$TG_TOKEN" ] || die "Telegram bot token required"
178
 
179
  echo ""
180
- echo " 3. Now open your bot in Telegram and send it any message — say \"hi\"."
181
- ask __continue "Press Enter once you've messaged the bot: "
182
-
183
- say "Looking up your Telegram user id from getUpdates..."
184
- USER_ID="$(curl -s "https://api.telegram.org/bot${TG_TOKEN}/getUpdates" | python3 -c "
185
- import json, sys
186
- try:
187
- d = json.load(sys.stdin)
188
- msgs = [u.get('message') or u.get('edited_message') or u.get('channel_post') for u in d.get('result', [])]
189
- ids = [str(m['from']['id']) for m in msgs if m and m.get('from', {}).get('id')]
190
- print(ids[-1] if ids else '')
191
- except Exception:
192
- print('')
193
- ")"
194
- if [ -n "$USER_ID" ]; then
195
- ok "Detected your Telegram user id: $USER_ID"
196
- else
197
- warn "Couldn't auto-detect. Enter it manually."
198
- ask USER_ID "Telegram numeric user id: "
199
- [ -n "$USER_ID" ] || die "Telegram user id required"
200
- fi
201
  fi
202
 
203
  # ----------------------------------------------------------------------------
 
177
  [ -n "$TG_TOKEN" ] || die "Telegram bot token required"
178
 
179
  echo ""
180
+ echo " 3. Now message @userinfobot on Telegram. It replies with your numeric"
181
+ echo " user id (looks like 123456789). Paste it below — this goes into"
182
+ echo " TELEGRAM_ALLOWED_USERS so only you can DM the bot."
183
+ echo ""
184
+ ask USER_ID "Your Telegram numeric user id: "
185
+ [ -n "$USER_ID" ] || die "Telegram user id required"
186
+ case "$USER_ID" in
187
+ *[!0-9]*) die "User id must be numeric (got: $USER_ID)" ;;
188
+ esac
189
+ ok "Telegram user id: $USER_ID"
 
 
 
 
 
 
 
 
 
 
 
190
  fi
191
 
192
  # ----------------------------------------------------------------------------