Answer the question
In order to leave comments, you need to log in
How to add a hyperlink to the Telegram bot button?
Hello!
There is a small Python code, using TelegramBotAPI (telebot)
import telebot
from telebot import types
bot = telebot.TeleBot('1388583270:AAHDIJbciOEzpUTU0y9XhDzDpbaxzybYNOI')
@bot.message_handler(commands=['start'])
def handle_start(message):
bot_l = telebot.types.ReplyKeyboardMarkup(True,False)
bot_l.row ('Отдел продаж')
bot_l.row ('Техподдержка','Бухгалтерия')
bot_l.row ('Адрес офиса','График работы')
bot_l.row ('Перейти на сайт')
bot.send_message(message.chat.id, 'Добро пожаловать в Telegram бот компании "Лайт". \nНажимая на кнопки, Вы сможете узнать номера телефонов, график работы, и другое.', reply_markup=bot_l)
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'Отдел продаж':
bot.send_message(message.chat.id, '8 (888) 888888, доб. 300')
elif message.text == 'Техподдержка':
bot.send_message(message.chat.id, '8 (888) 888888, доб. 301')
elif message.text == 'Бухгалтерия':
bot.send_message(message.chat.id, '8 (888) 888888, доб. 302')
elif message.text == 'Адрес офиса':
bot.send_message(message.chat.id, 'Наш адрес находится по адресу - адрес'
'Для удобства, Вы так же можете посмотреть расположение на карте ниже.')
bot.send_chat_action(message.chat.id, 'find_location')
bot.send_location(message.chat.id, 53.35570095764,83.7825186655)
elif message.text == 'График работы':
bot.send_message(message.chat.id, 'Понедельник: 9:00–17:30 \nВторник: 9:00–17:30 \nСреда: 9:00–17:30 \nЧетверг: 9:00–17:30 \nПятница: 9:00–17:00 \nСуббота: Выходной \nВоскресенье: Выходной')
elif message.text == 'Перейти на сайт':
bot.polling()
Answer the question
In order to leave comments, you need to log in
As written above, only through the inline keyboard.
Working code with examples below, finish as needed.
import telebot
from telebot import types
token = ""
bot = telebot.TeleBot(token)
contacs = {'sales': '8 (888) 888888, доб. 300',
'support': '8 (888) 888888, доб. 301',
'accounting': '8 (888) 888888, доб. 302',
'address': 'Наш адрес находится по адресу - адрес'}
@bot.message_handler(commands=['start'])
def handle_start(message):
keyboardmain = types.InlineKeyboardMarkup()
help = types.InlineKeyboardButton(text="Помощь", callback_data="help")
contacts = types.InlineKeyboardButton(text="Адрес офиса", callback_data="address")
site = types.InlineKeyboardButton(text="Перейти на сайт", callback_data="site", url='https://qna.habr.com/q/889613')
keyboardmain.add(help, contacts, site)
text = 'Добро пожаловать в Telegram бот компании "Лайт".'
bot.send_message(chat_id=message.chat.id, text=text, reply_markup=keyboardmain)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
keyboardmain = types.InlineKeyboardMarkup()
help = types.InlineKeyboardButton(text="Помощь", callback_data="help")
contacts = types.InlineKeyboardButton(text="Адрес офиса", callback_data="address")
site = types.InlineKeyboardButton(text="Перейти на сайт", callback_data="site", url='https://qna.habr.com/q/889613')
buttons = [help, contacts, site]
text = contacs.get(call.data, None)
if call.data == 'help':
accounting = types.InlineKeyboardButton(text="Бухгалтерия", callback_data="accounting")
support = types.InlineKeyboardButton(text="Техподдержка", callback_data="support")
sales = types.InlineKeyboardButton(text="Отдел продаж", callback_data="sales")
back = types.InlineKeyboardButton(text="Назад", callback_data="back")
buttons = [accounting, support, sales, back]
text = 'Выберите пункт меню: '
if call.data == 'accounting':
back = types.InlineKeyboardButton(text="Назад", callback_data="back")
buttons.append(back)
if call.data == 'support':
back = types.InlineKeyboardButton(text="Назад", callback_data="back")
buttons.append(back)
if call.data == 'sales':
back = types.InlineKeyboardButton(text="Назад", callback_data="back")
buttons.append(back)
if call.data == 'address':
back = types.InlineKeyboardButton(text="Назад", callback_data="back")
buttons.append(back)
keyboardmain.add(*buttons)
bot.send_message(chat_id=call.message.chat.id, text=text, reply_markup=keyboardmain)
if __name__ == "__main__":
try:
bot.polling(none_stop=True)
except Exception as Error:
print(Error)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question