I want to create an app that sends telegram messages to different people by phone number, and/or telegram id.
I’ve heard about the “Telegram Bot API”, but from my understanding it has some limitations (like it can’t send messages unless users authorize it and send the first message to it, and it doesn’t support sending messages using phone number)
And there is the “Telegram API”, which looks like a lot of work and coding..? I’m a 1 man developer and I don’t want to spend years to create a Telegram app from scratch that talks to telegram servers and does all the protocols and then I have to update it constantly and so on and so fourth.
I just want something that is easy to code & maintain, and can use my telegram account to programmatically send/receive messages. That’s it. Something like :
send.message(phone number, message)
or some sort of REST API that let’s me authenticate my telegram account and then provides methods that I can use to send messages to contacts.
Any ideas on how I can implement this? Any pointers would be appreciated!
2
Answers
Have a look at MTProto libraries like telethon or pyrogram. They are user-friendly (with lots of helper functions to abstract raw telegram api calls and their interfaces somewhat resemble the telegram bot api)
Here is a sample code (from the telethon docs):
Actually, telegram did a decent job to provide a powerful yet very simple API for its Bots (Attention: You can also use telegram applications like MadelineProto or telegram CLI to send messages and this is different from using Bot APIs. The applications are like your mobile/desktop app and use a real account with a particular authenticated phone numbers and you can do mostly anything that you can do with your phone app. But this is a different story).
For sending messages using bots, you can find all the documentations here. To use these APIs, you need:
With this sort of calling REST api, you can call many of the functions and this is only the first step and you can do much more complex and fun stuff! For many languages, there are some packages to work with the API which make everything simple and abstract to developers. A list of most popular packages could be found here.