2

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).

3
  • 2
    Welcome to Stack Overflow! We are a community of volunteers offering aid to programmers stuck on a particular task. We are not a service to write free code for you. Please read What topics can I ask about here? and How do I ask a good question? Commented Apr 6, 2017 at 14:31
  • @AlexHowansky you are right, i tried some lines but i totally stuck so i decided to ask from beginning! sorry about it Commented Apr 6, 2017 at 14:37
  • I think, if you replace "write me a template please?" on "How I can do it?", it can be exist in stackoverflow Commented Apr 6, 2017 at 14:57

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

tnx buddy! i found a stopwatch example and im try to do it! tnx :)
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.