0

I need to send a long message to a telegram group with a bot. The message comes from a wordpress site after placing an order,I need to send all raw data an order creates to the telegram. The bot and php code works so far, it is sending me the message if I type something basic, but when I put the order information it doesn´t send any message. I am looking for some code that somehow parses this information and makes it url ready to send to telegram.

This is my code:

     * SEND ORDER TO TELEGRAM GROUP
     */
        $apiToken = "Token";
        $data = [
              'chat_id' => 'ChatId',
              'text' => 'New Order, Open App'
          ];
        $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .http_build_query($data) );
     /**
     * SEND ORDER TO TELEGRAM GROUP
     */    

Maybe someone did it already previously? Thanks.

  • GET http verb has a limit of amount of characters that can be sent. Besides you need to show a minimum reproducible example. – nice_dev Feb 06 '23 at 05:49
  • https://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request – nice_dev Feb 06 '23 at 05:50
  • I am not able to see the raw output code, is there maybe some code to split everything in character limit? like if this $result = 2000 characters Split $result into 4 parts and send 4 http request http request 1: $result_part1 http request 2: $result_part2 http request 3: $result_part3 http request 4: $result_part3 – Florin Boneta Prats Feb 06 '23 at 06:05
  • No way to split like this. Use a POST request and send your data payload all at once. Also share telegram API link – nice_dev Feb 06 '23 at 06:09
  • The output should be something similar to this: Order type: Delivery Order status: Closed, Opened, On Hold Payment method: Cash on delivery Payment status: Paid, Not Paid, transfer Date: 2023-02-05 10:19pm Delivery address: long addresses Customer phone: +12123123123 4 x Pielmieni po ukraińsku 13 szt. (Mięso wieprzowo-wołowe, cebula, śmietana) The order products, can be really long, and can be short So maybe some php code to split the text into equal blocks? If possible, blocks without limit, so if needed 5 blocks, do 5 blocks, if needed 10 blocks, do 10 blocks. – Florin Boneta Prats Feb 06 '23 at 06:10
  • Could you please give an example? I don´t understand what you mean by post request and how to apply it here. – Florin Boneta Prats Feb 06 '23 at 06:11
  • Can you share the API documentation? – nice_dev Feb 06 '23 at 07:30
  • 4096 is the maximum amount of characters you can send in one message. If you need to split a longer message into multiple parts to send them one after the other, use something like `str_split`. – CBroe Feb 06 '23 at 08:08

0 Answers0