401 Unauthorized error after a year of successful using of Telegram API - telegram

Today when I as usually run my client to read income messages of my Telegram Bot I get the error
{"ok":false,"error_code":401,"description":"Unauthorized"}
I had been successfully used Telegram API every day during a year and never seen this error. I also didn't change any settings
What may happened?
At the page https://core.telegram.org/api/errors I read it's possible to get more detailed error description like AUTH_KEY_UNREGISTERED, AUTH_KEY_INVALID, USER_DEACTIVATED and so on.
But how can I do that?
Is it possible just to add something in the address bar to the request like https://api.telegram.org/bot<MY_TOKEN>/... ?

It may be helpful for someone.
I was not using my main account of Telegram associated with my phone number more than a year. That's why Telegram deleted my main account and accordingly my Telegram bot.

Related

How to send Telegram Message using Google Apps Script?

I have a basic Google App Script which is connected to a Google Sheet and sends a birthday reminder email on the day of someones birthday.
What I would like to do, is send an automated message on Telegram using the same data whilst inside of a group chat.
I don't want the message to come from a Bot account, but rather my own account so that it looks like I have genuinely sent the message myself. :)
Can this be done?
I have searched the web without success. Everything seems to be centered around creating a Bot account.

how to read/receive telegram channel messages in my telegram bot?

i'm trying to create a bot which can read/receive all messages in a specific channel and send them to me .
my problem here is that i can't find a way to access those messages in my bot
important thing is:
i'm not admin or creator of that channel
i don't want to ask the creator to add my bot as administrator
i've searched in google but i wasn't able to find a solution
and i'm also sure that it is possible to do it, because there are already some junction bots with exact same performance .
any references or suggestions are appreciated .
As already pointed out in the Telegram group of python-telegram-bot, bots can't receive messages from channels where they are not an admin. If you want something like this, you'll have to use a user bot, e.g. a program that controls your private Telegram account (in contrast to controlling a bot account). See here for some info on user bots.
Note that also the provider that you linked seems to be using userbots behind the scenes. More precisely, the docs on the so called "DirectConnection" state that you need to enter a phone number (associated to a telegram account) and then "Follow the instructions" which probably just means to enter the verification code that Telegram sends you. Phone number + verification code is exactly what is needed to control your private Telegram account.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

Make Telegram bot to read only /commands as administrator

I am using Telegram bot API with AWS Lambda and Zappa.
Everything was working fine. Until I realised that bot's webhook is being called everytime whenever a message is sent by anyone in the group.
I want to limit this webhook requests, as Lambda allows for only 1 million calls which is sufficient if bot is invoked, but only when /commands are called.
As I have to pin and edit messages using bot, that's why administrator permission is must.
I just want my bot to respond only to /commands along with administrator rights.
Please help me in tackling this issue.
I am assuming you added your bot to a Telegram group. In this case, the first thing that you need is group id. This should help: https://github.com/GabrielRF/telegram-id#web-group-id
And then you need to write a function that identifies the status of a chat member. You can do this using getChatMember method in Telegram Bots API.
If the chat member's status is "creator" or "administrator" then the response is sent to that user.
There are 2 things you need to do.
setPrivacy for your bot - go to BotFather chat and use the /setPrivacy command which gives you the ability to set:
'Enable' - your bot will only receive messages that either start with
the '/' symbol or mention the bot by username. (Should be default)
'Disable' - your bot
will receive all messages that people send to groups. Current status
is: DISABLED.
When setting the commands for the bot, set the BotCommandScopeAllChatAdministrators scope which should limit the use of the command only to the admins of the chat.

how to check if a user started a bot in telegram or not?

I'm developing a bot in telegram , here is my problem:
I have some posts in my channel which some inline_keyboards are attached to them. when a user press the button , next events happen in a bot and some messages show to a user. if user has been started the bot before , there is no problem , if not I have error. how should I check the user is member of my bot or not to handle this problem???
try to use sendMessage() API and send a message to user. After that telegram will response a status tell you whether success or not.
if started bot receive receive is ok,
if not started bot receive is nothing.
{"ok":true,"result":{"message_id":9999,"from":{"id":00000000,"is_bot":true,"first_name":"mybot","username":"mybot"}}}
like that, good luck.
There is no way to check if bot can talk to user or not without send message.
You can use url with https://t.me/Bot?start=some_data format, and you will receive /start some_data, please try this link yourself.
The problem with this approach is that if a lot of users do the same, telegram starts to throttle your callbacks :( ... it would be so much easier if you could just read that information somewhere...

How to get channel name in incoming message using only Telegram Bot API?

I'm working on one Telegram bot and faced a big problem: In order to exlude some "fraud" things one can do with my bot, I need to verify whether a user is admin in some channel or not. However, if user forward message from channel to bot, Chat.type parameter is still private, not channel.
Is there any way to get a pair user_id <--> in which channel user_id can post using only Bot API? Unfortunately, Inline mode doesn't help at all too.
Of course, I can use Telegram CLI for that, but in this particular situation it's prohibited.
As of May 6, 2016, a new field forward_from_chat is added to Message object. So my problem is solved.
More info about Message object: here

Resources