irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Home Page:https://telegram-bot-sdk.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

seaklong opened this issue · comments

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

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.

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,

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.

$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 ?