Untitled
unknown
python
2 years ago
1.3 kB
5
Indexable
import datetime import telegram bot_token = 'token here' public_channel_id = '@enter id here' my_channel_id = '@enter id here' # Calculate the start and end times for the current day today = datetime.datetime.today().date() start_time = datetime.datetime.combine(today, datetime.time.min) end_time = datetime.datetime.combine(today, datetime.time.max) # Create a bot object and use it to get the chat history of the public channel bot = telegram.Bot(token=bot_token) messages = bot.get_chat_history(chat_id=public_channel_id, limit=None, from_date=start_time, to_date=end_time) # Forward each message to your channel for message in messages: # Forward the message text text = message.text or '' bot.send_message(chat_id=my_channel_id, text=text) # Forward any attachments (e.g. photos, videos, documents) for attachment in message.document or []: bot.send_document(chat_id=my_channel_id, document=attachment) for attachment in message.photo or []: bot.send_photo(chat_id=my_channel_id, photo=attachment) for attachment in message.video or []: bot.send_video(chat_id=my_channel_id, video=attachment) for attachment in message.voice or []: bot.send_voice(chat_id=my_channel_id, voice=attachment)
Editor is loading...