J
J
Jemoro2021-09-14 16:41:28
Python
Jemoro, 2021-09-14 16:41:28

How to implement these tasks in Python?

Today I started making my second Telegram bot, I write naturally in Python, without using third-party libraries.

During the development process, I encountered some tasks, I coped with most of them, but some remained beyond my little knowledge in this area.

1 Task
You have the following code:

@bot.message_handler(commands = ['url'])
def url(message):
    markup = types.InlineKeyboardMarkup()
    btn_my_site= types.InlineKeyboardButton(text='Написать ей', url='https://habrahabr.ru')
    markup.add(btn_my_site)
    bot.send_photo(message.chat.id, get("https://im0-tub-ru.yandex.net/i?id=ad7b5dc2baef00695b93f71305f81888-l&n=13").content, reply_markup=main4())
    bot.send_message(message.chat.id, "Татьяна, 22 года.", reply_markup = markup)


Description of the problem and question: As far as you could understand, this is a url format button, I need to make sure that after running the command, the bot displays (text, photo, url button) and all this in one message. No matter how much I tried, I could not do this thing. Looking forward to your help, thanks in advance)

2 Task

I have the following code:

@bot.message_handler(content_types=['text'])
def cont(message):
    if message.text == 'Смотреть анкеты':
        bot.send_message(message.chat.id,"Текст", reply_markup=markup)


Description of the problem and question: It is required to make the bot, when the message 'View profiles' is found, display the profile from the above. Thanks in advance for the answers)

I apologize for such a little impudence, but no matter how much I searched on Google, I did not find anything worthwhile. I just don’t have the strength, I searched the entire Internet today and found nothing.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vasily Bannikov, 2021-09-14
@vabka

bot.send_photo(message.chat.id, get("https://im0-tub-ru.yandex.net/i?id=ad7b5dc2baef00695b93f71305f81888-l&n=13").content, reply_markup=main4())
    bot.send_message(message.chat.id, "Татьяна, 22 года.", reply_markup = markup)

It's strange, and why is it sent with two different messages?)
Just insert a picture as an html link into a text message. Naturally, you also need to enable the markup parsing mode in html.
"Without third-party libraries" this is done through the parse_mode parameter of the sendMessage method.
This is how the link should look like: In general, this is a hack, since the feature of the cart is exploited here, that a preview of the link content is attached to the message. And in the case of the picture, this preview is large enough to be comfortably viewed.
<a href="тут ссылка на картинку">&#8205;</a>

S
Stefan, 2021-09-14
@MEDIOFF

1 Task: As you can see from your code, you didn't try or search Google for anything, because if you just because if you went to the documentation for the method bot.send_photoof the library that you DO NOT USE, you would see the caption argument or similar, and reply_markup and you wouldn't have such questions.
2 Task: Well, just send this message in the same way as in the handler above, what's the problem then?

S
Sali_cat, 2014-09-11
@Sali_cat

<? header("Location: /путь к файлу");?>
Well, don't forget about http"s" header

P
Pavel Belousov, 2014-09-10
@PafNutY

if ($str) {
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: /");
  exit();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question