Set chat permissions via telegram bot

Question:

I want to add a function to the bot "change chat permissions" and I can’t figure out how to do it.
Using an aiogram lib with postgresql database (psycopg2)

Python 3.9.5
aiogram==2.14.3

Callback handler (for example: call.data = "defaultchat-can_send_media_messages")

@dp.callback_query_handler(lambda call: "defaultchat" == call.data.split('-')[0])
async def deafultChatCallbacks(call: types.callback_query):
    chatLang = pg.getChatLang(call.message.chat.id)
    call_data = call.data.split('-')[1]
    curSettings = pg.getChatSettings(call.message.chat.id) # :rtype: dict (in db it's json)

    curSettings[call_data] = not curSettings[call_data]
    
    # Trying change the type from dict to types.ChatPermissions
    curSettings = type('types.ChatPermissions', (type,), (curSettings))
    return await call.message.chat.set_permissions(permissions=curSettings)

Dict (or json in Database):

{
    'can_send_messages': True, 
    'can_send_media_messages': True, 
    'can_send_polls': True, 
    'can_send_other_messages': True, 
    'can_add_web_page_previews': True, 
    'can_change_info': True, 
    'can_invite_users': True, 
    'can_pin_messages': True
}

Log:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-10' coro=<Dispatcher._process_polling_updates() done, defined at D:Program FilesPythonlibsite-packagesaiogramdispatcherdispatcher.py:409> exception=BadRequest("Can't parse permissions json object")>
...
aiogram.utils.exceptions.BadRequest: Can't parse permissions json object

If i remove the line with changing the class # curSettings = type('types.ChatPermissions', (type,), (curSettings)) here is log:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-10' coro=<Dispatcher._process_polling_updates() done, defined at D:Program FilesPythonlibsite-packagesaiogramdispatcherdispatcher.py:409> exception=BadRequest('Chat_not_modified')>
...
aiogram.utils.exceptions.BadRequest: Chat_not_modified
Asked By: rvbsm

||

Answers:

I can’t test it but based on telegram-bot issues Append/Update on ChatPermissions you should do

curSettings = ChatPermissions(**curSettings)
Answered By: furas