Class: Viberroo::Message

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

Overview

This class’ methods serve as declarative wrappers with predefined types for each message type Viber API offers.

Class Method Summary collapse

Class Method Details

.contact(params = {}) ⇒ Hash

Contact message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • contact (Hash)
  • contact.name (Float)

    Required. Name of the contact. Max 28 characters.

  • contact.phone_number (Float)

    Required. Phone number of the contact. Max 18 characters.

Returns:

  • (Hash)

See Also:

[View source]

160
161
162
# File 'lib/viberroo/message.rb', line 160

def self.contact(params = {})
  { type: :contact }.merge(params)
end

.file(params = {}) ⇒ Hash

Note:

Max file size is 50MB.

File message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • media (String)

    Required. File URL.

  • size (Integer)

    Required. File size in bytes.

  • file_name (String)

    Required. Name of the file, should include extension. Max 256 characters (including extension).

Returns:

  • (Hash)

See Also:

[View source]

144
145
146
# File 'lib/viberroo/message.rb', line 144

def self.file(params = {})
  { type: :file }.merge(params)
end

.location(params) ⇒ Hash

Location message.

Examples:

message = Message.location(location: { lat: '48.9215', lon: '24.7097' })

Parameters:

  • params (Hash)

Options Hash (params):

  • location (Hash)
  • location.lat (Float)

    Required. Latitude

  • location.lon (Float)

    Required. Longitude

Returns:

  • (Hash)

See Also:

[View source]

88
89
90
# File 'lib/viberroo/message.rb', line 88

def self.location(params)
  { type: :location }.merge(params)
end

.picture(params = {}) ⇒ Hash

Note:

Max image size: 1MB on iOS, 3MB on Android.

Picture message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • media (String)

    Required. Image URL. Allowed extensions: .jpeg, .png .gif. Animated GIFs can be sent as URL messages or file messages.

  • text (String)

    Optional. Max 120 characters.

  • thumbnail (String)

    Optional. Thumbnail URL. Max size 100 kb. Recommended: 400x400.

Returns:

  • (Hash)

See Also:

[View source]

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

def self.picture(params = {})
  { type: :picture, text: '' }.merge(params)
end

.plain(params) ⇒ Hash

Simple text message.

Examples:

message = Viberroo::Message.plain(text: 'Hello there!')

Parameters:

  • params (Hash)

Options Hash (params):

  • text (String)

    Required.

Returns:

  • (Hash)

See Also:

[View source]

22
23
24
# File 'lib/viberroo/message.rb', line 22

def self.plain(params)
  { type: :text }.merge(params)
end

.rich(params) ⇒ Hash

The Rich Media message type allows sending messages with pre-defined layout, including height (rows number), width (columns number), text, images and buttons.

Examples:

Send a rich media

search = Button.reply({
  Columns: 4,
  Rows: 3,
  ActionBody: '/search',
  Text: 'Search something...'
}

locate = Button.reply({
  Columns: 4,
  Rows: 3,
  ActionBody: '/near_me'
}

browse = Button.url({
  Columns: 4,
  Rows: 2,
  ActionBody: 'parrot.live',
  Text: 'Browse something wierd'
}

@bot.send_rich_media(
  rich_media: {
    ButtonsGroupColumns: 4,
    ButtonsGroupRows: 6,
    Buttons: [search, locate, browse]
  }
)

Parameters:

  • params (Hash)

Options Hash (params):

  • rich_media (Hash)
  • rich_media.ButtonsGroupColumns (Integer)

    Number of columns per carousel content block. Possible values 1 - 6. **API Default**: 6.

  • rich_media.ButtonsGroupRows (Integer)

    Number of rows per carousel content block. Possible values 1 - 7. **API Default**: 7.

  • rich_media.Buttons (Hash)

    Array of buttons. Max of 6 * ‘ButtonsGroupColumns` * `ButtonsGroupRows`.

Returns:

  • (Hash)

See Also:

[View source]

69
70
71
# File 'lib/viberroo/message.rb', line 69

def self.rich(params)
  { type: :rich_media, min_api_version: 2 }.merge(params)
end

.sticker(params = {}) ⇒ Hash

Sticker message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • sticker_id (Integer)

    Required. Max 2000 characters.

Returns:

  • (Hash)

See Also:

[View source]

189
190
191
# File 'lib/viberroo/message.rb', line 189

def self.sticker(params = {})
  { type: :sticker }.merge(params)
end

.url(params = {}) ⇒ Hash

URL message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • media (String)

    Required. Max 2000 characters.

Returns:

  • (Hash)

See Also:

[View source]

174
175
176
# File 'lib/viberroo/message.rb', line 174

def self.url(params = {})
  { type: :url }.merge(params)
end

.video(params = {}) ⇒ Hash

Note:

Max video size is 26MB.

Video message.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • media (String)

    Required. URL of the video (MP4, H264). Only MP4 and H264 are supported.

  • size (Integer)

    Required. Size of the video in bytes.

  • duration (Integer)

    Optional. Duration in seconds. Max value - 180.

  • thumbnail (String)

    Optional. Thumbnail URL. Max size 100 kb. Recommended: 400x400. Only JPEG format is supported.

Returns:

  • (Hash)

See Also:

[View source]

125
126
127
# File 'lib/viberroo/message.rb', line 125

def self.video(params = {})
  { type: :video }.merge(params)
end