telegram bot reply message for buttons

Question:

recently i created a telegram bot using python and i added keyboard button features to the bot. However, i am having difficulties in getting replies from bot to the buttons users choose.

button7 = KeyboardButton('About Us',request_contact= False)
keyboard2 = ReplyKeyboardMarkup(resize_keyboard = True, one_time_keyboard = True).row(button7)
@dp.message_handler(commands=['info'])
async def mood(message: types.Message):
    await message.reply('Do you wish to know about us??', reply_markup=keyboard2)

In this case, i created a button named "About Us" and i want the bot to open a url using webbrowser.open if the user click on that button. Can anyone help me solving this problem?

Asked By: Yogendran Prakash

||

Answers:

Try it:

markup = types.InlineKeyboardMarkup()
button1 = types.InlineKeyboardButton(text='Ukraine', url="https://en.wikipedia.org/wiki/Ukraine", callback_data='1')
markup.add(button1)
bot.send_message(message.from_user.id, 'Do you know?, parse_mode='Markdown', reply_markup=markup)

Text (inline button)

from aiogram import Bot, Dispatcher, executor, types

bot = Bot(token='token')
dp = Dispatcher(bot)


@dp.message_handler(commands=['start'])
async def welcome(message: types.Message):
    markup = types.InlineKeyboardMarkup()
    button1 = types.InlineKeyboardButton(text='Ukraine', url="https://en.wikipedia.org/wiki/Ukraine", callback_data='1')
    button2 = types.InlineKeyboardButton(text='Hi bot!', callback_data="1")
    markup.add(button1, button2)

    await bot.send_message(message.from_user.id, "Do you know?", parse_mode="Markdown", reply_markup=markup)


@dp.callback_query_handler(lambda call: True)
async def sendText(call: types.CallbackQuery):
    msg = ""
    if call.data == "1":
        msg = "Hi, programmer!"

    await call.message.edit_text(msg)


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)
Answered By: ogelcast