7

I program the bot telegram.

I want Get message_id By Bot ,when I sent a message to Group.

My Code is PHP.

$token = "MY_BOT's_TOKEN";

$data = [
    'text' => 'my message here',
    'chat_id' => 'the_chat_id_here'
];

file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );

How Do it?

best regard.

hamed hossani
  • 986
  • 2
  • 14
  • 33
  • 1
    share some of your code and specify which library you are using. – tashakori Jul 31 '17 at 08:05
  • 1
    i changed my answer. – hamed hossani Jul 31 '17 at 09:27
  • 2
    i am not expert in php, but follow these steps: $response =file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) ); echo $response; now you know the structure of the json response, then write a code to parse the json result and to extract the messageID. – tashakori Jul 31 '17 at 09:38
  • 1
    I Do it.But noting return.it is empty. ```$result=$this->send_message ( $data );``` – hamed hossani Jul 31 '17 at 10:37
  • 2
    why don't you use these well coded APIs? https://github.com/unreal4u/telegram-api https://github.com/php-telegram-bot/core if you use these libraries, you won't need to handle connection issues. and you also won't need to somehow invent the wheel again. – tashakori Jul 31 '17 at 10:45
  • thanks . I try work by that link, – hamed hossani Jul 31 '17 at 15:31
  • Mr @tashakori your answer is correct.when massage has been send ,return result message.has {ok="",message_id} – hamed hossani Aug 01 '17 at 02:43

1 Answers1

7

Your file_get_contents call returns a result containing status code and messageId.

$result = file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );
tashakori
  • 2,331
  • 1
  • 22
  • 29