Viber - Hide the user field input when sending Keyboard Message

Viewed 1215

I'm trying to send a Text Message with a keyboard. I found in the docs that I can hide the input field of the user by setting the value of InputFieldState to hidden but the user input field is still there when I send the message.

Expected Behavior enter image description here

Actual Behavior enter image description here

4 Answers

Try this. Define the keyboard

const KEYBOARD_JSON = {
 "Type": "keyboard",
 "InputFieldState": "hidden",
 "Buttons": [{ // This is just an example
    "Columns": 6,
    "Rows": 1,
    "ActionType": "reply",
    "ActionBody": "Get started",
    "Text": "Get started",
    "BgColor": "#F0923F",
    "TextSize": "regular",
    "TextHAlign": "center",
    "TextVAlign": "middle",
    "Silent": "true"
 }]
}

define the message using the KeyboardMessage constructor with the below optional arguments.

const your_message = new KeyboardMessage(KEYBOARD_JSON, null, null, null, 3); // If it didn't work with min_api_version 3, try 4

Viber documentation is not good enough. As I tried, You should include "min_api_version": 4 in the JSON message.

Try this: "InputFieldState": "minimized".

Here is an example

keyboard": {
    "Type": "keyboard",
    "InputFieldState": "minimized",
    "Buttons": [
      {
        "Columns": "2",
        "Rows": "2",
        "BgColor": "#000000",
        .....
        .....
      }

If you send a TextMessage without a keyboard and then send KeyBoardMessage it's working.

Something like this :

bot.sendMessage(
      response.userProfile,
      new TextMessage('Test message')
    );

    setTimeout(() => {
      bot.sendMessage(
        response.userProfile,
        new KeyboardMessage(
          your_keyboard,
          null,
          null,
          null,
          3
        )
      );
    }, 500);

But I still can't find a way to send TextMessage with hidden input field. Because doing it like this when the TextMessage is sent, the input field will occur and after some time when the KeyBoardMessage arrives it will hide it, and that isn't something that we are looking for :)

Related