Search code examples
pythonaiogram

callback data get string instead bool aiogram


Aiogram 2v. When i use callback data, instead bool i get string. How can i fix this in aiogram 2? I know how to do it in aiogram 3, but it beta.

callback_data = faq_callback.new(action='faqAct' ,id=int(i.get('id')),iftext=bool(hastext)))

But i get "True" "False". How i can get bool?


Solution

  • If you always get a value in 'True' and 'False' in string format you can convert them to bool by comparing with 'True':

    callback_data = faq_callback.new(action='faqAct' ,id=int(i.get('id')),iftext=bool(hastext))) == 'True'
    

    So, it will compare faq_callback.new() with string 'True' ; if it is correct it will give Boolean True; if faq_callback.new() is 'False' it will give Boolean False .

    Both these Boolean True/False will be assigned to callback_data