Class: Viberroo::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/viberroo/input.rb

Overview

This class’ methods serve as declarative wrappers with predefined types for UI elements such as buttons and keyboards. Buttons can be combined with a keyboard or used in rich messages. Only basic parameters are specified in this documentation, to see all possibilities please consult official Viber API documentation.

Class Method Summary collapse

Class Method Details

.keyboard(params) ⇒ Object

A keyboard that can be attached to any message.

Examples:

go_somewhere = Viberroo::Input.url_button({
  Columns: 3,
  Rows: 2,
  Text: 'Mystery link',
  ActionBody: 'somewhere.com'
})

keyboard = Input.keyboard(Buttons: [go_somewhere])

See Also:

[View source]

28
29
30
# File 'lib/viberroo/input.rb', line 28

def self.keyboard(params)
  { keyboard: { Type: 'keyboard' }.merge(params) }
end

.location_picker_button(params) ⇒ Object

Note:

Not supported on desktop.

Location picker button, gives ability to pick a location on the map.

Examples:

button = Viberroo::Input.location_picker_button(location: { lat: 48.9215, lon: 24.7097 })

See Also:

[View source]

76
77
78
79
80
# File 'lib/viberroo/input.rb', line 76

def self.location_picker_button(params)
  { ActionType: 'location-picker',
    min_api_version: 3
  }.merge(params)
end

.none_button(params = {}) ⇒ Object

A button that does nothing, for decoration purposes.

Examples:

button = Viberroo::Input.none_button(Text: 'Purely decorative.')

See Also:

[View source]

106
107
108
# File 'lib/viberroo/input.rb', line 106

def self.none_button(params = {})
  { ActionType: 'none' }.merge(params)
end

.reply_button(params) ⇒ Object

A reply button, when tapped sends it’s body as a message.

Examples:

button = Viberroo::Input.reply_button({
  Columns: 4,
  Rows: 3,
  ActionBody: '/search_cookies',
  Text: 'I want some cookies.'
}

See Also:

[View source]

45
46
47
# File 'lib/viberroo/input.rb', line 45

def self.reply_button(params)
  { ActionType: 'reply' }.merge(params)
end

.share_phone_button(params) ⇒ Object

Note:

Not supported on desktop.

Share phone button.

Examples:

button = Viberroo::Input.share_phone_button(contact: { name: 'Gwythyr', phone_number: '12343214' })

See Also:

[View source]

92
93
94
95
96
# File 'lib/viberroo/input.rb', line 92

def self.share_phone_button(params)
  { ActionType: 'share-phone',
    min_api_version: 3
  }.merge(params)
end

.url_button(params) ⇒ Object

A URL button, when tapped opens specified URL.

Examples:

button = Viberroo::Input.url_button({
  Columns: 4,
  Rows: 2,
  ActionBody: 'parrot.live',
  Text: 'Browse something weird'
}

See Also:

[View source]

62
63
64
# File 'lib/viberroo/input.rb', line 62

def self.url_button(params)
  { ActionType: 'open-url' }.merge(params)
end