Answer the question
In order to leave comments, you need to log in
How to add https to telebot link?
I use the telebot library for bots.
The problem is, I can't process the link. The scenario is this, the user enters a link, but it happens that the link can be short, without https, www, for example - test.ru. I need to do such processing so that the bot itself adds https and www, and if the user specifies a full link, i.e. from https://www.test.ru , then everything is OK and go to the next step.
When the user presses - start, the function is called:
@bot.callback_query_handler(func=lambda message: True)
def send_anytext(message):
chat_id = message.message.chat.id
if message.data == 'utm_links':
msg = bot.send_message(chat_id, 'Введите адрес сайта в формате https://domain.ru/\n\nНапример, https://yandex.ru/', parse_mode='HTML')
bot.register_next_step_handler(msg, get_utm_source)
def get_utm_source(message):
global get_utm_source;
get_utm_source = message.text;
chat_id = message.chat.id
msg = bot.send_message(chat_id, "Введите сообщение")
bot.register_next_step_handler(msg, get_utm_medium)
def convert(url):
if url.startswith('http://www.'):
return 'http://' + url[len('http://www.'):]
if url.startswith('www.'):
return 'http://' + url[len('www.'):]
if not url.startswith('http://'):
return 'http://' + url
return url
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question