custom states not updating
PhenomAmd opened this issue · comments
PhenomAmd commented
Please answer these questions before submitting your issue. Thanks!
-
What version of pyTelegramBotAPI are you using?
4.16.1 -
What OS are you using?
Windows 10 -
What version of python are you using?
3.11.8
Custom state always returns None no matther what in this source:
from telebot import asyncio_filters
from telebot.async_telebot import AsyncTeleBot
from telebot.asyncio_storage import StateMemoryStorage
from telebot.asyncio_handler_backends import State, StatesGroup
bot = AsyncTeleBot("7142173773:AAFzIzrbwotLP8IG4ALGy3i3Jt5jg4QDzbc",state_storage=StateMemoryStorage())
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
import asyncio
class MyStates(StatesGroup):
state1 = State() # statesgroup should contain states
def gen_markup():
markup = InlineKeyboardMarkup()
markup.row_width = 1
markup.add(InlineKeyboardButton("Yes", callback_data="cb_yes"))
return markup
@bot.message_handler(commands=['k'])
async def send_welcome(message):
cid = message.chat.id
message.text.replace("/k ","").splitlines()
#some process with data
await bot.send_message(cid,f"Proceed to step2",reply_markup=gen_markup())
@bot.callback_query_handler(func=lambda call: True)
async def callback_query(call):
cid, uid= call.message.chat.id, call.from_user.id
if call.data == "cb_yes":
await bot.answer_callback_query(call.id, "Callback reached")
x = await bot.set_state(uid, MyStates.state1, cid)
print(x)
await bot.send_message(cid, "Processing")
@bot.message_handler(state=MyStates.state1)
async def chktransf(message):
await bot.send_message(message.chat.id, "Has reached this state!")
bot.add_custom_filter(asyncio_filters.StateFilter(bot)) #dont need isdigit filter as im not processing digits
asyncio.run(bot.polling(skip_pending=True))
perhaps i am missing something ?
Vlad Chuenko commented
You must hide your bot token. It is not safe!
>_run commented
make sure you are passing valid user_ids and chat_ids into relevant fields.