1

I see some bots acts regarding args passed to the bot. For example:

https://t.me/name_bot?start=something

This is helpful for sending invitations/ referral / promo codes etc.

How can I handle this using python-telegram-bot and getting the start value?

Is it possible to use different vars other than start?

AKMalkadi
  • 782
  • 1
  • 5
  • 18

1 Answers1

1

I never tested it before but it seems you have it in documentation as deep linking.

start=something should run command /start something

Link can use only start or startgroup


import os
import telegram
from telegram.ext import Updater, CommandHandler

# --- init ---

TOKEN = os.getenv('TELEGRAM_TOKEN')

updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher

# --- commands ---

def start(update, context):
    print('text:', update.message.text)   # /start something
    print('args:', context.args)          # ['something']

dispatcher.add_handler(CommandHandler('start', start))

# --- start ---
    
updater.start_polling()
updater.idle()
furas
  • 134,197
  • 12
  • 106
  • 148