button

A text followed by one or more buttons.

button(text=String, buttons=Array/Hash, params=Hash)

Platforms

Usage

Reply

@reply.button(
  "Hello, how can I help today?",
  [
    {
      title: "Create an account",
      payload: "profile/create_account"
    },
    {
      title: "Read TOS",
      payload: "read_tos"
    },
    {
      title: "Feature Product",
      payload: set_payload("products/view", { product_id: 10 })
    }
  ]
)

On-Demand

user.notification.button(
  "Hello, how can I help today?",
  [
    {
      title: "Create an account",
      payload: "profile/create_account"
    },
    {
      title: "Read TOS",
      payload: "read_tos"
    },
    {
      title: "Feature Product",
      payload: set_payload("products/view", { product_id: 10 })
    }
  ]
)
user.notification.send()

In either case, the click event will be captured by a postback block (if declared) in the context defined in the payload route.

Payload formats

To the same context

"read_tos"

To a different context

"profile/create_account"

With params

set_payload("products/view", { product_id: 10 })

Arguments

Extra params

Below are some unified or built-in parameters from this framework.

typed_postbacks

Regardless of the value of config.typed_postbacks in the main configuration, this feature can be enabled/disabled independently passing this parameter with true or false.

@reply.button(
  "Hello, how are you today?",
  [
    {
      title: "Good",
      payload: "good_mood"
    },
    {
      title: "Bad",
      payload: "bad_mood"
    }
  ],
  { typed_postbacks: true }
)

slice_replies

Only available in Telegram, it allows displaying a defined amount of buttons in rows.

@reply.button(
  "Choose a number from 1 to 10",
  (1..10).map{|number|
    {
      title: "Number: #{number}",
      payload: set_payload(:number_response,{ number: number})
    }
  },
  { slice_replies: 3  }
)  

For more information, read more about the expected params for each platform:

Last updated