Patrick Ian Co
Patrick Ian Co

Reputation: 345

Viber - Hide the user field input when sending Keyboard Message

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

Upvotes: 2

Views: 1915

Answers (4)

nlee
nlee

Reputation: 15

Try this: "InputFieldState": "minimized".

Here is an example

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

Upvotes: 1

Si Quy Lee
Si Quy Lee

Reputation: 19

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

Upvotes: 1

Pece Krstevski
Pece Krstevski

Reputation: 11

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 :)

Upvotes: 0

root
root

Reputation: 151

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

Upvotes: 3

Related Questions