NicoNex / echotron

An elegant and concurrent library for the Telegram bot API in Go.
https://t.me/s/echotronnews
GNU Lesser General Public License v3.0
363 stars 26 forks source link

Method restrictChatMember doesn't work if ChatPermissions are wrapped with PermissionOptions #34

Closed dpogibenko closed 1 year ago

dpogibenko commented 1 year ago

Hello! I've faced a problem with applying user permissions. Function restrictChatMember from api.go uses function serializePerms where struct ChatPermissions is wrapped with PermissionOptions.

Output looks like this and such representation is ignored by telegram server: permissions={"permissions":{"can_send_messages":true}}

If I change code so ChatPermissions isn't wrapped it works well: permissions={"can_send_messages":true}

This code doesn't work for me:

func serializePerms(permissions ChatPermissions) (string, error) {
    perm, err := json.Marshal(PermissionOptions{permissions})
    if err != nil {
        return "", err
    }
    return string(perm), nil
}

And this works:

func serializePerms(permissions ChatPermissions) (string, error) {
    perm, err := json.Marshal(permissions)
    if err != nil {
        return "", err
    }
    return string(perm), nil
}

Is it bug or my mistake?

DjMike238 commented 1 year ago

Hi @dpogibenko, I'm really sorry for the really late answer, but things happened and I only just now managed to check this issue.

I just pushed the fix (fabc7ad), it is now available in the latest version of Echotron, v3.27.0.

Thanks for the heads up!