Automate posting messages to a Telegram channel via API
Asked Answered
C

3

31

I am new to the Telegram API. I would like to automate posting messages to my public telegram channel. I read a few posts that with bots I can achieve this, but I am not sure if that's the best way and whether the API has an option to directly post to a channel.

I would like to get some start points on how to achieve this? Which API should I use? Whether I need a dev account or bot, etc?

Centavo answered 22/2, 2016 at 7:16 Comment(0)
C
23

After 1 year of working with telegram API, I wanted to update this answer for best possible ways to interact with telegram API.

For posting to channels, both telegram API and telegram bot API can post to channels.

I worked directly with both the APIs, but I found the following clients for telegram API and bot API to be faster and easier to interact with telegram.

Telegram API client:

https://github.com/LonamiWebs/Telethon

Telegram bot API:

https://github.com/python-telegram-bot/python-telegram-bot

Centavo answered 22/7, 2017 at 6:16 Comment(2)
How should one use these? can you please add some more explanation?Singlephase
@trix Go to the github pages listed above, both projects have good explanation on their first pages how to set them up in no time. Of course you need some basic knowledge of python, but other than that the readme on the first pages are very self explanatory.Centavo
P
31

You can use bots to send message to channels. But there is some limitation, like size of files.

  1. create your bot, by sending message to @botfather
  2. add the bot to your channel. stackoverflow
  3. write a code to send message to your channel. bot api
Parfitt answered 8/2, 2017 at 9:43 Comment(1)
Let me add 2 interesting links to help a bit more on the 3th step:: 1- Use more specifically the method core.telegram.org/bots/api#sendmessage , 2- If your channel is private you can get the chat id as described here: kerkour.com/telegram-bot-send-messages-to-private-channelLister
C
23

After 1 year of working with telegram API, I wanted to update this answer for best possible ways to interact with telegram API.

For posting to channels, both telegram API and telegram bot API can post to channels.

I worked directly with both the APIs, but I found the following clients for telegram API and bot API to be faster and easier to interact with telegram.

Telegram API client:

https://github.com/LonamiWebs/Telethon

Telegram bot API:

https://github.com/python-telegram-bot/python-telegram-bot

Centavo answered 22/7, 2017 at 6:16 Comment(2)
How should one use these? can you please add some more explanation?Singlephase
@trix Go to the github pages listed above, both projects have good explanation on their first pages how to set them up in no time. Of course you need some basic knowledge of python, but other than that the readme on the first pages are very self explanatory.Centavo
O
-1

It is impossible to read messages from Telegram channels using Telegram Bot API.

In order to be able to scrape messages from Telegram channels that you do not own, you need to develop you own Telegram client that is capable of:

  1. Joining your desired channels by links
  2. Forwarding messages, arriving to the channels your client is subscribed to, to your own Telegram channel

In order to develop your own Telegram client, you need to use some implementation of MTProto.

You can find a lot of implementations of MTProto on https://github.com using mtproto keyword.

A few examples of well-documented implementations:


But probably it would be an overkill to develop your own solution to this problem if the only thing you want is to have several redirections from existing Telegram channels to your own channel.

There are applications that provide such a service.

For example, there is MultiFeed Bot from telespace.me team:

It allows you to setup forwarding of messages within Telegram as well as redirections to external services.

Outgrow answered 24/7, 2018 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.