2

I set a webhook with telegram and basically use this code to send messages to telegram from my server:

header("Content-Type: application/json");  
$parameters = array('chat_id' => xxx, "text" => "hi there");
$parameters["method"] = "sendMessage";
echo json_encode($parameters);  

and this all works.
The problem is that I can't send two messages one after the other.

I tried echoing two times:

header("Content-Type: application/json");   
$parameters = array('chat_id' => xxx, "text" => "hi there");
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
$parameters["text"] = "hi everybody";
echo json_encode($parameters);

and I tried sending an array of messages:

header("Content-Type: application/json");   
$parameters = array('chat_id' => xxx, "text" => array("hi there", "hi everybody"));
$parameters["method"] = "sendMessage";
echo json_encode($parameters);

both with no success.
What am I doing wrong??

Ferex
  • 553
  • 6
  • 22

1 Answers1

2

I had the same issue and managed to get an answer from Telegram support. Their response:

"No, only one single method can be called when answering to a webhook request, sorry."

The workaround for me was to simply use regular API requests. You can make multiple requests from your code before (or even instead of) outputting the webhook response.

https://core.telegram.org/bots/api#making-requests

dubious
  • 31
  • 2