Задать вопрос
  • Хочу написать простое Web App приложение в telegram и не понимаю почему код не работает?

    from aiogram import Bot, Dispatcher, types
    from aiogram.filters import Command
    from aiogram.types import WebAppInfo
    import asyncio
    
    # Создание бота
    bot = Bot(token="MY_Token")
    dp = Dispatcher()
    
    # Хэндлер для команды /start
    @dp.message(Command("start"))
    async def start(message: types.Message):
        # Создание клавиатуры с веб-приложением
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        button = types.KeyboardButton(
            text="Открыть страницу",
            web_app=WebAppInfo(url="https://www.avito.ru/")  # URL веб-приложения
        )
        markup.add(button)
        
        # Отправка сообщения с клавиатурой
        await message.answer("Hello!", reply_markup=markup)
    
    # Асинхронная функция для запуска бота
    async def main():
        await dp.start_polling(bot)
    
    # Точка входа
    if __name__ == "__main__":
        asyncio.run(main())
    Ответ написан
    Комментировать
  • Бот отвечает только на /start, остальное игнорирует. Почему?

    import telebot
    from telebot import types
    
    bot = telebot.TeleBot("TOKEN")
    
    @bot.message_handler(commands=['start'])
    def send_welcome(message):
        bot.send_message(message.chat.id, 'Приветствие'.format(message.from_user, bot.get_me()), parse_mode='html')
    
    @bot.message_handler(content_types=['text', 'photo'])
    def send_reply(message):
        if message.text:
            text = message.text.lower()  # Приводим текст сообщения к нижнему регистру
            if text == 'привет':
                bot.send_message(message.chat.id, 'Ответ')
            elif text == 'текст_1':
                bot.send_photo(message.chat.id, 'URL')
            elif text == 'текст_2':
                bot.send_photo(message.chat.id, 'URL')
            elif text == 'текст_3':
                bot.send_photo(message.chat.id, 'URL')
            elif text == 'текст_4':
                bot.send_photo(message.chat.id, 'URL')
            elif text == 'текст_5':
                bot.send_photo(message.chat.id, 'URL')
            else:
                bot.send_message(message.chat.id, 'Я тебя не понимаю...')
        elif message.photo:
            bot.send_message(message.chat.id, 'Вы отправили фото!')
    
    bot.polling(none_stop=True)
    Ответ написан
    Комментировать