Answer the question
In order to leave comments, you need to log in
InlineKeyboardMarkup ReplyKeyboardMarkup how to make it appear after one message?
Please tell me that when you press the start command, an inline keyboard appears with the choice of "Ukrainian" and "English"
and a replica with the phrases "beginning" and "end" also appears, and that this keyboard is always in the bot. Tell me how to do it?
CODE
import config
import telebot
from telebot import types
from requests import get
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def inline(message):
key = types.InlineKeyboardMarkup()
but_1 = types.InlineKeyboardButton(text="Ukrainian", callback_data="Ukrainian")
but_2 = types.InlineKeyboardButton(text="English", callback_data="
bot.send_photo(message.chat.id,open("C:\\EMB.jpg","rb"))
bot.send_message(message.chat.id, "Good afternoon" + message.from_user.first_name + ", I am a chat bot of Kyiv Medical University. Glad to welcome you. Please choose the language of communication.", reply_markup=key)
@ bot.callback_query_handler(func=lambda c:True)
def ukraine(c):
if c.data == 'Ukrainian':
key = types.InlineKeyboardMarkup()
but_1 = types.InlineKeyboardButton(text="Intro", callback_data="Intro ")
but_2 = types.InlineKeyboardButton(text="Last degree of education", callback_data="Last degree of education")
but_3 = types.InlineKeyboardButton(text="Student", callback_data="Student")
but_4 = types.InlineKeyboardButton(text="Contact ID", callback_data="Contact ID")
but_5 = types.InlineKeyboardButton(text="Payment Details ", url=" https://kmu.u.ua/oplata/ ")
key.add(but_1, but_2)
key.add(but_3, but_4)
key.add(but_5)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True )
item1 = types.KeyboardButton("Eb")
item2 = types.KeyboardButton("Kіnets")
markup.add(item1, item2)
bot.send_message(c.message.chat.id, 'Bless me if you like me. ', reply_markup=key)
Answer the question
In order to leave comments, you need to log in
It was evening, there was nothing. I smashed it into modules, but you'll figure it out (everything is in one directory). In some places I redid it, in some places I added english. The main thing is to follow the structure first callback on inline, then on the reply button. Instead of a picture, I smeared a sticker, well, it was so that it was at hand.
PS Don't forget to insert your token into cfg.
Main.py (Main module)
# -*- coding: utf-8 -*-
import telebot, cfg, kb, lg
from telebot import types
from requests import get
bot = telebot.TeleBot(cfg.token)
@bot.message_handler(commands=['start'])
def start(message):
bot.send_sticker(message.chat.id, "CAACAgUAAxkBAAIHg18CC9ooVxBjT62AL3MZT_liQgUtAAKJAwAC6QrIA9kfvAIjYHAXGgQ") #bot.send_photo(message.chat.id,open("C:\\ЕМБ.jpg","rb"))
bot.send_message(message.chat.id, lg.hello1u + message.from_user.first_name + lg.hello2u)
bot.send_message(message.chat.id, lg.hello1e + message.from_user.first_name + lg.hello2e, reply_markup=kb.ikb1)
@bot.callback_query_handler(func=lambda c:True)
def cbinline(c):
if c.data == lg.ukr:
bot.send_message(c.message.chat.id, lg.razdelu, reply_markup=kb.ikb2u)
bot.send_message(c.message.chat.id, lg.umusthave ,reply_markup=kb.rkbu)
elif c.data == lg.eng:
bot.send_message(c.message.chat.id, lg.razdele, reply_markup=kb.ikb2e)
bot.send_message(c.message.chat.id, lg.emusthave ,reply_markup=kb.rkbe)
elif c.data == lg.ibtn1u:
bot.send_message(c.message.chat.id, lg.txt1u)
elif c.data == lg.ibtn2u:
bot.send_message(c.message.chat.id, lg.txt2u)
elif c.data == lg.ibtn3u:
bot.send_message(c.message.chat.id, lg.txt3u)
elif c.data == lg.ibtn4u:
bot.send_message(c.message.chat.id, lg.txt4u)
elif c.data == lg.ibtn5u:
bot.send_message(c.message.chat.id, lg.txt5u)
elif c.data == lg.ibtn1e:
bot.send_message(c.message.chat.id, lg.txt1e)
elif c.data == lg.ibtn2e:
bot.send_message(c.message.chat.id, lg.txt2e)
elif c.data == lg.ibtn3e:
bot.send_message(c.message.chat.id, lg.txt3e)
elif c.data == lg.ibtn4e:
bot.send_message(c.message.chat.id, lg.txt4e)
elif c.data == lg.ibtn5e:
bot.send_message(c.message.chat.id, lg.txt5e)
@bot.message_handler(content_types=['text'])
def cbreply(message):
if message.text == lg.rbtn1u:
bot.send_message(message.chat.id, lg.hello1u + message.from_user.first_name + lg.hello2u)
bot.send_message(message.chat.id, lg.hello1e + message.from_user.first_name + lg.hello2e, reply_markup=kb.ikb1)
elif message.text == lg.rbtn2u:
bot.send_message(message.chat.id, lg.endu, reply_markup=kb.kbsu)
elif message.text == lg.rbtn1e:
bot.send_message(message.chat.id, lg.hello1u + message.from_user.first_name + lg.hello2u)
bot.send_message(message.chat.id, lg.hello1e + message.from_user.first_name + lg.hello2e, reply_markup=kb.ikb1)
elif message.text == lg.rbtn2e:
bot.send_message(message.chat.id, lg.ende, reply_markup=kb.kbse)
if __name__ == '__main__':
bot.polling(none_stop=True)
token = 'цыфры:буквы'
url = "https://kmu.u.ua/oplata/"
# -*- coding: utf-8 -*-
import telebot, lg, cfg
from telebot import types
#Это сокращения клавитарских выражений
tikm = types.InlineKeyboardMarkup
trkm = types.ReplyKeyboardMarkup
tikb = types.InlineKeyboardButton
#start
ikb1 = tikm()
ibtn1 = tikb(text=lg.ukr, callback_data=lg.ukr)
ibtn2 = tikb(text=lg.eng, callback_data=lg.eng)
ikb1.add(ibtn1, ibtn2)
#Ukr main kb
ikb2u = tikm()
ibtn1 = tikb(text=lg.ibtn1u, callback_data=lg.ibtn1u)
ibtn2 = tikb(text=lg.ibtn2u, callback_data=lg.ibtn2u)
ibtn3 = tikb(text=lg.ibtn3u, callback_data=lg.ibtn3u)
ibtn4 = tikb(text=lg.ibtn4u, callback_data=lg.ibtn4u)
ibtn5 = tikb(text=lg.ibtn5u, url=cfg.url)
ikb2u.add(ibtn1, ibtn2)
ikb2u.add(ibtn3, ibtn4)
ikb2u.add(ibtn5)
#Eng main kb
ikb2e = tikm()
ibtn1 = tikb(text=lg.ibtn1e, callback_data=lg.ibtn1e)
ibtn2 = tikb(text=lg.ibtn2e, callback_data=lg.ibtn2e)
ibtn3 = tikb(text=lg.ibtn3e, callback_data=lg.ibtn3e)
ibtn4 = tikb(text=lg.ibtn4e, callback_data=lg.ibtn4e)
ibtn5 = tikb(text=lg.ibtn5e, url=cfg.url)
ikb2e.add(ibtn1, ibtn2)
ikb2e.add(ibtn3, ibtn4)
ikb2e.add(ibtn5)
#Tostart/toend
rkbu = trkm(True, True, row_width=1)
rkbu.add(lg.rbtn1u, lg.rbtn2u)
rkbe = trkm(True, True, row_width=1)
rkbe.add(lg.rbtn1e, lg.rbtn2e)
#End keyboard
kbsu = trkm(True, True, row_width=1)
kbsu.add(lg.rbtn1u)
kbse = trkm(True, True, row_width=1)
kbse.add(lg.rbtn1e)
#Buttons
ukr = "Українська"
eng = "English"
ibtn1u = "Вступ"
ibtn2u = "Післядипломна освіта"
ibtn3u = "Студенту"
ibtn4u = "Довідник контактів"
ibtn5u = "Реквізити-Оплата"
ibtn1e = "Introduction"
ibtn2e = "Postgraduate education"
ibtn3e = "To student"
ibtn4e = "Contacts Directory"
ibtn5e = "Details-Payment"
rbtn1u = "Початок"
rbtn2u = "Кінець"
rbtn1e = "To the begining"
rbtn2e = "To the end"
#Text
hello1u = "Доброго дня "
hello2u = ", Я бот-консультант Київського медичного Університету. Радий Вас вітати.Оберіть будь ласка мову спілкування.\n"
hello1e = "Good day "
hello2e = "I am a chat bot of Kyiv Medical University. Glad to welcome you. Please choose the language of communication."
razdelu = "Оберіть будь ласка розділ який Вас цікавить."
razdele = "Please select the section that interests you."
umusthave = "Також ви можете перемещатся за допомогою кнопок внизу."
emusthave = "You can also navigate using the buttons below."
txt1u = "Это текст после нажатия 'Вступ'"
txt2u = "Это текст после нажатия 'Післядипломна освіта'"
txt3u = "Это текст после нажатия 'Студенту'"
txt4u = "Это текст после нажатия 'Довідник контактів'"
txt5u = "Это текст после нажатия 'Реквізити-Оплата'"
txt1e = "Это текст после нажатия 'Introduction'"
txt2e = "Это текст после нажатия 'Postgraduate education'"
txt3e = "Это текст после нажатия 'To student'"
txt4e = "Это текст после нажатия 'Contacts Directory'"
txt5e = "Это текст после нажатия 'Details-Payment'"
endu = "Вы попали в конец!"
ende = "You in the end!"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question