MoKhajavi75
MoKhajavi75

Reputation: 2702

Message sending Telegram bot (PHP)

I know it's somehow weird to ask something like this, but I'm trying to program a telegram bot with PHP.

The bot is in a channel (e.g. Channel A) and I'm going to send messages in that channel, so the bot will copy X number of messages to another channel (Channel B), Every Y minutes.

Example:

X = 5
Y = 60
Channel A = ID .....
Channel B = ID .....

So it will COPY 5 messages from A to B every hour...

Can anybody write me a template please? I think I can configure the VPS and webhook stuff (SSL and etc).

Upvotes: 2

Views: 1802

Answers (2)

TheFaultInOurStars
TheFaultInOurStars

Reputation: 3608

If you want to use webhook things you can do this.

write a sample code like this:

<?php
    $texts_from_other_channel = [];
    array_push($texts_from_other_channel , $update_array['message']['text']);
    $t_size = sizeof($texts_from_other_channel)
    for($i=0 ; $i < $t_size ; $i++){
        $post_prs = ['chat_id' => $channel_id , 'text' => $texts_from_other_channel[$i]];
        send_reply($sendmessag_url , $post_prs);
    end

?>

other things like send_reply() function or $update_array are up to you and I left to yourself.

Upvotes: 1

Maxim Tkach
Maxim Tkach

Reputation: 1677

If you need send message per minutes, and get message from Telegram callback, you need read about queue (zmq, redis, gearman or etc).

  1. Create daemons. These are your bots. They can read messages from queue and send callbacks.
  2. Write Controller to get callback from telegram. It can take message and push to queue.
  3. Install Ev or Event extension on PHP. (You can use reactphp, it simple solution to create timer)
  4. Bot1 create timer, and listen messages. If we have more 5 messages, timer can push message in queue for Bot2.

You can use reactphp/zmq, nrk/predis-async to helpful your task

P.S. It is most simple solution. But you can use pthreads (instead create daemon process) or use simple socket to send message in bot.

Upvotes: 4

Related Questions