unreal4u / telegram-api

Complete async capable Telegram bot API implementation for PHP7
https://github.com/unreal4u/telegram-api/wiki
MIT License
791 stars 174 forks source link

Exception unreal4u\TelegramAPI\Exceptions\ClientException caught, message: Bad Request: chat not found #113

Closed venkycc closed 4 years ago

venkycc commented 4 years ago

Hello

The get-chat-member.php example throws the above exception "Exception unreal4u\TelegramAPI\Exceptions\ClientException caught, message: Bad Request: chat not found"

My settings are correct and I am able to send messages directly to the value defined for "$A_USER_CHAT_ID": Direct messages are sent like below (after the usual includes for the autoload and the config files)

Note: i use variables with $ everywhere, that's the only difference between the example and my code


use \unreal4u\TelegramAPI\HttpClientRequestHandler;
use \unreal4u\TelegramAPI\TgLog;
use \unreal4u\TelegramAPI\Telegram\Methods\SendMessage;

$loop = \React\EventLoop\Factory::create();
$handler = new HttpClientRequestHandler($loop);
$tgLog = new TgLog($MyBotToken, $handler);

$sendMessage = new SendMessage();
$sendMessage->chat_id = $A_USER_CHAT_ID;
$sendMessage->text = 'Hello worlddddddddddd 222222!';

$tgLog->performApiRequest($sendMessage);
$loop->run();

I used the username as found in the mobile app/settings/username . I tried both with "myname" as well as "@myname" (of course, without the quotes and with the actual name in settings instead of myname)

Any help/ thoughts will be welcome

unreal4u commented 4 years ago

Hi!

A user chat id is normally a number, which you will get once you start a chat with your bot in the form of an update (either retrievable via getUpdates or via Webhook). You can also send a message to the bot and this will appear as a new message which will include the user chat id as well.

This number is the one you must use: a bot can not initiate a conversation with a user.

I hope this information can help you further. Otherwise, you can always check out the wiki for some more documentation ( https://github.com/unreal4u/telegram-api/wiki/Getting-updates-via-Webhook ) or ask via our group: t.me/phpbotapi

Thanks!

venkycc commented 4 years ago

Hi

Thanks for the response.

Yes, I do understand. I use the webhook.

In the webhook, for example, it included the following:

        [date] => 1578662339
        [chat] => unreal4u\TelegramAPI\Telegram\Types\Chat Object
            (
                [id] => 111111111 

I tried with "A_USER_CHAT_ID" set to the above (replaced actual number with a dummy number) and A_USER_ID set to both "username" as well as "@username".

Both resulted in the same error on examples get-chat-member.php and on get-user-profile-photos.php examples.

However, the example "send-message-with-keyboard-options.php" works perfectly fine with the same settings in the config

Any ideas please? THanks

venkycc commented 4 years ago

Command not available for bots