Creating a PHP-based Telegram bot for message replication

Hey everyone! I’m trying to build a Telegram bot using PHP. I’m a bit stuck and could use some help.

Here’s what I want the bot to do:

  1. The bot will be in one channel (let’s call it Channel A).
  2. It needs to copy a certain number of messages from Channel A.
  3. Then paste those messages into another channel (Channel B).
  4. This should happen automatically every set number of minutes.

For example, I want it to copy 5 messages from Channel A to Channel B every 60 minutes.

I’ve got some experience with setting up VPS and webhook stuff, including SSL. But I’m having trouble with the actual bot code.

Can anyone share a basic template or point me in the right direction? I’d really appreciate any help or advice you can offer. Thanks in advance!

hey zack, i’ve done something like this before. you’ll need to use the telegram bot api for sure. getUpdates method can grab messages from channel A, then sendMessage to post em in B. for the timing part, set up a cron job to run ur script every hour. make sure u got the right permissions for both channels tho!

I’ve implemented a similar bot for my company’s internal communication. Here’s what worked for me:

First, set up a webhook to receive updates from Telegram. This is more efficient than polling.

Use the getUpdates method to fetch messages from Channel A. Store the message IDs you’ve processed to avoid duplicates.

For sending to Channel B, I found sendMediaGroup useful for batching multiple messages, which is more efficient than individual sendMessage calls.

To handle the timing, I used a simple MySQL database to track when the last batch was sent. The script checks this timestamp and only proceeds if enough time has passed.

One gotcha: watch out for message types. Some, like polls, can’t be directly forwarded. You might need to recreate them.

Hope this helps with your project!

Having created a similar Telegram bot using PHP, I can share my experience. The crucial step is using the Telegram Bot API to manage message transfers between channels. Begin by retrieving messages from the source channel using the getChatHistory method and follow this by replicating them in the destination channel with the sendMessage method. For continuous operation, implement a cron job to run your script at regular intervals—say, every 60 minutes. Ensure that messages are temporarily stored before sending, and pay attention to rate limits, error handling, and appropriate channel permissions.