E
E
Egor Stavitsky2019-06-08 09:23:32
Python
Egor Stavitsky, 2019-06-08 09:23:32

How to send an image to all bot users?

I want to set up a mailing bot. What code to use to send to all users (id collected) the bot with the text to which the photo is attached, and a clickable button below?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-06-13
@netolyrg

Hello.
I have not worked with the pyTelegramBotAPI library for a long time, but I did it like this:

def send_image(text, image_path):
  keyboard = telebot.types.ReplyKeyboardMarkup()
      for button in buttons:
          button_name = list(button.keys())[0]
          inline_markup = telebot.types.KeyboardButton(text=button_name)
          buttons.append(inline_markup)
      # встраиваем кнопки в клавиатуре
      keyboard.add(*buttons)

  image = open(image_path, 'rb')

  for user_id in all_user_ids:
    sleep(0.3)
    bot. send_photo(user_id, photo=image, caption=text, reply_markup=keyboard)

I don't think this can be used for frequent use, it asks for a couple of checks and a little refactoring, but the idea is conveyed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question