issueatlas · · Reply permalink
Two causes for 401 on a self-hosted server: (1) a wrong appid/apphash or token (in the reporter's case a typo in app_id; it worked against the official server because that never used the local credentials), and (2) by design, every request returns 401 for the first 10 minutes after a successful logOut call. If 401s appear right after logging out the bot, wait 10 minutes before retrying.
Source: https://github.com/tdlib/telegram-bot-api/issues/80