Eleirbag89 / TelegramBotPHP

A very simple PHP Telegram Bot API for sending messages.
http://eleirbag89.github.io/TelegramBotPHP
MIT License
800 stars 340 forks source link

Bad Request: chat_id is empty #225

Closed mohsenmehribusiness closed 3 years ago

mohsenmehribusiness commented 3 years ago

hi when time i,m read this not worked :

$BOT_TOKEN="myTokenId"; $telegram = new Telegram($BOT_TOKEN); $chat_id = $telegram->ChatID(); $content = array('chat_id' => $chat_id, 'text' => 'test is good'); $telegram->sendMessage($content);

but when time i,m read this worked : `$BOT_TOKEN="myTokenId"; $telegram = new Telegram($BOT_TOKEN); //$chat_id = $telegram->ChatID(); $content = array('chat_id' => 112358796, 'text' => 'test is good'); $telegram->sendMessage($content);

this text error : ============[Date]============ [ 2020-10-30 03:45:28 Europe/Berlin ] ==========[Response]========== ok: False error_code: 400 description: Bad Request: chat_id is empty =========[Sent Data]========== [ref] ref.chat_id= ref.text= test is good

============[Trace]===========

0 C:\Users\RAYANGOSTAER2\Documents\bot telegram\vendor\eleirbag89\telegrambotphp\Telegram.php(3201): TelegramErrorLogger::log(Array, Array)

1 C:\Users\RAYANGOSTAER2\Documents\bot telegram\vendor\eleirbag89\telegrambotphp\Telegram.php(111): Telegram->sendAPIRequest('https://api.tel...', Array)

2 C:\Users\RAYANGOSTAER2\Documents\bot telegram\vendor\eleirbag89\telegrambotphp\Telegram.php(196): Telegram->endpoint('sendMessage', Array)

3 C:\Users\RAYANGOSTAER2\Documents\bot telegram\index.php(7): Telegram->sendMessage(Array)

4 {main}

JOSDC01 commented 3 years ago

Use:

$BOT_TOKEN="Your_Token";

$telegram = new Telegram($BOT_TOKEN);

$result = $telegram->getData(); $text = $result['message'] ['text']; $chat_id = $result['message']['chat']['id'];

if($text == /test){ $msg= 'Test is good'; $content = array('chat_id' => $chat_id, 'text' => $msg); $telegram->sendMessage($content); }

shibin-pb commented 3 years ago

I'm also getting similar error

============[Date]============ [ 2021-01-19 05:49:34 UTC ] ==========[Response]========== ok: False error_code: 400 description: Bad Request: chat_id is empty =========[Sent Data]========== [ref] ref.chat_id= ref.text= Test

============[Trace]===========

0 /var/www/html/telegram/Telegram.php(3217): TelegramErrorLogger::log(Array, Array)

1 /var/www/html/telegram/Telegram.php(111): Telegram->sendAPIRequest('https://api.tel...', Array)

2 /var/www/html/telegram/Telegram.php(196): Telegram->endpoint('sendMessage', Array)

3 /var/www/html/telegram/test.php(41): Telegram->sendMessage(Array)

4 {main}

I have used the following php code

$BOT_TOKEN="Your_Token";

$telegram = new Telegram($BOT_TOKEN); $result = $telegram->getData(); $text = $result['message'] ['text']; $chat_id = $result['message'] ['chat']['id']; $content = array('chat_id' => $chat_id, 'text' => 'Test'); $telegram->sendMessage($content);

Please help me to sort it out..

Eleirbag89 commented 3 years ago

How the bot is configured ? Using the webhook ?

shibin-pb commented 3 years ago

I haven't used webhook ? and i'm not getting chat id automatically by this script and it is required to enter chat id manually to send telegram notification message

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.