telegram-bot-sdk icon indicating copy to clipboard operation
telegram-bot-sdk copied to clipboard

How to get reply_to_message for sendMessage?

Open sanzharanarbay opened this issue 4 years ago • 1 comments

$telegram = new Api(Telegram::getAccessToken()); $update = Telegram::getWebhookUpdates(); $chat_id = $update->getMessage()->getChat()->getId();

    $replyMarkup = array(
        'force_reply' => true
    );
    $encodedMarkup = json_encode($replyMarkup);
	
    $response = $telegram->sendMessage([
        'chat_id' => $chat_id,
        'text' => 'Enter your name , please?',
        'reply_markup' => $encodedMarkup
    ]);

// this gives me entered command, not name $text = $update->getMessage()->getText();

$this->replyWithMessage(['text' => 'Hello, ' . $text]);

sanzharanarbay avatar Sep 26 '20 15:09 sanzharanarbay

Hi @sanzharanarbay you can check if ther's any 'reply_to_message' in the response from user like the code below.

  public function commandHandlerWebHook()
  {
      $updates = Telegram::commandsHandler(true);
      $chat_id = $updates->getChat()->getId();

      // get Reply_to_message
      if(array_key_exists('reply_to_message', $updates['message'])) {
        Telegram::sendMessage(['chat_id' => $chat_id, 'text' => 'Hello ' . $updates['message']['text']]);
      }

      return 'ok';
    }

you can put the code in your webhook route. It's work fine.

egin10 avatar Jan 24 '21 05:01 egin10