irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.04k stars 671 forks source link

why webhook cannot get message response offset-1 from user? #1046

Closed seaklong closed 1 year ago

seaklong commented 1 year ago

PHP version

8

irazasyed/telegram-bot-sdk version

3.9

Laravel version (if any)

8

Code To Reproduce the bug

$telegram = new Api(env('TELEGRAM_BOT_TOKEN'));

    $response = $telegram->removeWebhook();

    $response = $telegram->getUpdates();

    $telegram->sendMessage([
        'text' => 'my text',
        'parse_mode' => 'HTML',
        'force_reply' => true 
    ]);

Error stacktrace (if any)

Conflict: can't use getUpdates method while webhook is active; bot not response message and get message from the user. please kindly help

irazasyed commented 1 year ago

You can't use getUpdates() method when a webhook is enabled. I'm not sure what issue you're facing either.

Please clarify what you're trying to achieve.

seaklong commented 1 year ago

webhook can get last text message (offset -1) response from the user or not?

after delete webhook and use getUpdates like below:

$response = $telegram->getUpdates();

$telegram->sendMessage([
    'text' => 'my text',
    'parse_mode' => 'HTML',
    'force_reply' => true 
]);

Bot not response or display text message in chat. i need:
Bot response and get update text message from the user for select database then response again to the user and always get last text message (offset -1). please kindly help,

irazasyed commented 1 year ago

Webhook always gets the latest update.

getUpdates method on the other hand returns all the pending updates.

You should then iterate over all the updates and process them or use the commands handler to automatically handle the commands.

To respond, you need to provide the chat_id when sending a message.

seaklong commented 1 year ago

$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => 'my text', 'reply_markup' => $reply_markup, 'parse_mode' => 'HTML', 'force_reply' => true ]); but nothing send or response from bot and user. can you give me a sample config and example ?

irazasyed commented 1 year ago

Explore the docs here: https://telegram-bot-sdk.com/docs/