9

I have a custom keyboard but to process the answer i need a force reply so i get the question back in the next message. I have done this:

var opts = {
    reply_markup: JSON.stringify({ 
        keyboard: [['OK','Cancel']],
        one_time_keyboard: true,
        resize_keyboard: true,
        force_reply: true
    })
};

The keyboard works but not the force_reply. Force reply on its own works? Can i not use it in combination with a custom keyboard?

Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35
Peter Newman
  • 91
  • 1
  • 1
  • 3

2 Answers2

7

It may be late to help you, but here it goes.

Currently only one reply_markup field is allow and this field must contain only one of the following types: ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply (see docs)

In any case, you can use ReplyKeyboardMarkup that will pop up a custom keyboard in the user app directly and code your bot so it only accept one of the answer in your own custom keyboards.

Furthermore, if you really want to force that the user reply, you can keep sending the same ReplyKeyboardMarkup after each user's invalid answer.

Ruben Bermudez
  • 2,293
  • 14
  • 22
2

You need to specify your markup like this :

$replyMarkup = array(
  'force_reply' => true,
  'selective' => true
);

If you need to have custom keyboard you can follow this :

$keyboradsValue = array(
   array("button 1","button 2"),
   array("button 3","button 4"),
);
$replyMarkup = array(
  'keyboard' => $keyboradsValue,
  'force_reply' => true,
  'selective' => true
);

After that you need to encode your object using json_encode

$encodedMarkup = json_encode($replyMarkup, true);

Finally you just put above code at your query string at the rest of sendMessage.

Hamed
  • 565
  • 3
  • 17
  • Did you actually try this? – ramazan polat Jan 16 '18 at 01:54
  • If you want to do something you have to call a function. After clicking keyboard by user, That function should be called, After that, The result return to user by another keyboard or display something to user by the URL query which Telegram gave to you. – Hamed May 13 '18 at 10:17