Ошибка при использовании calendar-telegram
Выдаёт ошибку!!!
ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: can\'t parse reply keyboard markup JSON object"}']"
https://github.com/unmonoqueteclea/calendar-telegram
import telebot
import traceback
import telegramcalendar
import datetime
class Bot:
"""docstring for bot"""
def __init__(self, token):
self.server_name="bot"
self.tg=telebot.TeleBot(token=token)
self.tg_m=telebot.types
def sms(self,chat_id,text,parse_mode=None,reply_to_message_id=None,reply_markup=None):
self.tg.send_message(chat_id=chat_id,text=text,parse_mode=parse_mode,reply_to_message_id=reply_to_message_id,reply_markup=reply_markup)
def means(self,message):
message=message
try:
Return=message
except: Return=""
if Return!="":
chat_id=message.chat.id
user_id=message.from_user.id
message_id=message.message_id
msg=message.text
try:
first_name=message.from_user.first_name
except:
first_name=""
try:
last_name=" "+message.from_user.last_name
except:
last_name=""
return chat_id, user_id, message_id, first_name, last_name,msg
def get(self,chat_id):
r=self.tg.get_chat_members_count(chat_id=chat_id)
return r
def photo(self,chat_id,file_id=None,file_size=None,caption=None,parse_mode=None):
self.tg.send_photo(chat_id=chat_id,photo=file_id,caption=caption,parse_mode=parse_mode)
def button(self,text=None):
R=self.tg_m.ReplyKeyboardMarkup(resize_keyboard=True,one_time_keyboard=True)
R.row('/start','hello')
return R
def start(self):
while True:
try:
@self.tg.message_handler(commands=['start'])
def answer(message):
chat_id, user_id, message_id, first_name, last_name=self.means(message=message)
markup=self.button()
self.sms(chat_id=chat_id,text="Welcome my master.",reply_markup=markup)
@self.tg.message_handler(commands=['calendar'])
def calendar_handler(message):
chat_id, user_id, message_id, first_name, last_name, msg = self.means(message=message)
now = datetime.datetime.now() #Текущая дата
date = (now.year,now.month)
markup = telegramcalendar.create_calendar(now.year,now.month)
self.tg.send_message(chat_id=chat_id, text="Пожалуйста, выберите дату",reply_markup=markup)
@self.tg.message_handler(content_type=["text"])
def answer_1(message):
chat_id, user_id, message_id, first_name, last_name=self.means(message=message)
if message.text=='hello':
print("123")
self.sms(chat_id=chat_id,text="Hi.\nHow are you?")
try:
self.tg.polling(none_stop=True,interval=0)
except Exception as e:
try:
print(traceback.format_exc())
self.sms(chat_id="your_telegram_id",text="Error!\n"+traceback.format_exc())
except:
print(traceback.format_exc())
except Exception as e:
try:
print(traceback.format_exc())
self.sms(chat_id="your_telegram_id",text="Error!\n"+traceback.format_exc())
except:
print(traceback.format_exc())
bot=Bot(token="token")
bot.start()
А это telegramcalendar.ру
from telegram import InlineKeyboardButton, InlineKeyboardMarkup,ReplyKeyboardRemove
import datetime
import calendar
def create_callback_data(action,year,month,day):
""" Create the callback data associated to each button"""
return ";".join([action,str(year),str(month),str(day)])
def separate_callback_data(data):
""" Separate the callback data"""
return data.split(";")
def create_calendar(year=None,month=None):
"""
Create an inline keyboard with the provided year and month
:param int year: Year to use in the calendar, if None the current year is used.
:param int month: Month to use in the calendar, if None the current month is used.
:return: Returns the InlineKeyboardMarkup object with the calendar.
"""
now = datetime.datetime.now()
if year == None: year = now.year
if month == None: month = now.month
data_ignore = create_callback_data("IGNORE", year, month, 0)
keyboard = []
#First row - Month and Year
row=[]
row.append(InlineKeyboardButton(calendar.month_name[month]+" "+str(year),callback_data=data_ignore))
keyboard.append(row)
#Second row - Week Days
row=[]
for day in ["Mo","Tu","We","Th","Fr","Sa","Su"]:
row.append(InlineKeyboardButton(day,callback_data=data_ignore))
keyboard.append(row)
my_calendar = calendar.monthcalendar(year, month)
for week in my_calendar:
row=[]
for day in week:
if(day==0):
row.append(InlineKeyboardButton(" ",callback_data=data_ignore))
else:
row.append(InlineKeyboardButton(str(day),callback_data=create_callback_data("DAY",year,month,day)))
keyboard.append(row)
#Last row - Buttons
row=[]
row.append(InlineKeyboardButton("<",callback_data=create_callback_data("PREV-MONTH",year,month,day)))
row.append(InlineKeyboardButton(" ",callback_data=data_ignore))
row.append(InlineKeyboardButton(">",callback_data=create_callback_data("NEXT-MONTH",year,month,day)))
keyboard.append(row)
return InlineKeyboardMarkup(keyboard)
def process_calendar_selection(bot,update):
"""
Process the callback_query. This method generates a new calendar if forward or
backward is pressed. This method should be called inside a CallbackQueryHandler.
:param telegram.Bot bot: The bot, as provided by the CallbackQueryHandler
:param telegram.Update update: The update, as provided by the CallbackQueryHandler
:return: Returns a tuple (Boolean,datetime.datetime), indicating if a date is selected
and returning the date if so.
"""
ret_data = (False,None)
query = update.callback_query
(action,year,month,day) = separate_callback_data(query.data)
curr = datetime.datetime(int(year), int(month), 1)
if action == "IGNORE":
bot.answer_callback_query(callback_query_id= query.id)
elif action == "DAY":
bot.edit_message_text(text=query.message.text,
chat_id=query.message.chat_id,
message_id=query.message.message_id
)
ret_data = True,datetime.datetime(int(year),int(month),int(day))
elif action == "PREV-MONTH":
pre = curr - datetime.timedelta(days=1)
bot.edit_message_text(text=query.message.text,
chat_id=query.message.chat_id,
message_id=query.message.message_id,
reply_markup=create_calendar(int(pre.year),int(pre.month)))
elif action == "NEXT-MONTH":
ne = curr + datetime.timedelta(days=31)
bot.edit_message_text(text=query.message.text,
chat_id=query.message.chat_id,
message_id=query.message.message_id,
reply_markup=create_calendar(int(ne.year),int(ne.month)))
else:
bot.answer_callback_query(callback_query_id= query.id,text="Something went wrong!")
# UNKNOWN
return ret_data
