Class: RubyVibe::Bot

Inherits:
Client show all
Defined in:
lib/ruby-vibe/bot.rb

Overview

Set of predefined viber api requests. This class is used directly by user. Define constants for configuration settings, or add them on initialization.

Examples:

Set default configuration

RubyVibe::TOKEN  = 'my_viber_auth_token'
RubyVibe::NAME   = 'my_viber_nickname'
RubyVibe::AVATAR = 'avatar_url'

Instance Attribute Summary

Attributes inherited from Client

#avatar, #name, #payload_hash, #response, #token

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, name: nil, avatar: nil) ⇒ Bot

Returns Bot object to work with.

Examples:

Initialize new bot with user-defined configuration

@bot = RubyVibe::Bot.new(token:  'auth_token',
                         name:   'sender_name',
                         avatar: 'https_avatar_url' )

Parameters:

  • token (String) (defaults to: nil)

    Optional. Auth token provided by Viber.

  • name (String) (defaults to: nil)

    Optional. Sender name provided by user.

  • avatar (String) (defaults to: nil)

    Optional. SSL link to user photo.



28
29
30
31
32
33
34
# File 'lib/ruby-vibe/bot.rb', line 28

def initialize(token: nil, name: nil, avatar: nil)
  token  ||= RubyVibe::TOKEN
  name   ||= RubyVibe::NAME
  avatar ||= RubyVibe::AVATAR

  super(token: token, name: name, avatar: avatar)
end

Instance Method Details

#broadcast_message(opts = {}) ⇒ Hash

Broadcast message to multiple users.

Parameters:

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

    Viber API options for broadcast_message request

Options Hash (opts):

  • message (String)

    Required. Message text

  • receivers (Array)

    Required. Message receivers

  • sender_name (String)

    Optional. Sender name || RubyVibe::NAME

  • avatar (String)

    Optional. Avatar url || RubyVibe::AVATAR

  • keyboard (String)

    Optional. Add keyboard to message

  • rich_media (String)

    Optional. Send rich_media message

Returns:

  • (Hash)

    Response hash defined in RubyVibe::Client

See Also:



72
73
74
75
76
# File 'lib/ruby-vibe/bot.rb', line 72

def broadcast_message(opts = {})
  opts.merge!(type: 'text') unless opts[:type]
  
  viberize(URL::BROADCAST_MESSAGE, opts)
end

#get_account_infoObject



88
89
90
# File 'lib/ruby-vibe/bot.rb', line 88

def 
  viberize(URL::GET_ACCOUNT_INFO, info: true)
end

#get_online(*user_ids) ⇒ Object



102
103
104
# File 'lib/ruby-vibe/bot.rb', line 102

def get_online(*user_ids)
  viberize(URL::GET_ONLINE, ids: Array(user_ids), info: true)
end

#get_user_details(user_id) ⇒ Object



95
96
97
# File 'lib/ruby-vibe/bot.rb', line 95

def get_user_details(user_id)
  viberize(URL::GET_USER_DETAILS, id: user_id, info: true)
end

#send_message(opts = {}) ⇒ Hash

Send message to user.

Parameters:

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

Options Hash (opts):

  • message (String)

    Required. Message text

  • receiver (String)

    Required. Message receiver

  • sender_name (String)

    Optional. Sender name || RubyVibe::NAME

  • avatar (String)

    Optional. Avatar url || RubyVibe::AVATAR

  • keyboard (String)

    Optional. Add keyboard to message

  • rich_media (String)

    Optional. Send rich_media message

Returns:

  • (Hash)

    Response hash defined in RubyVibe::Client

See Also:



51
52
53
54
55
# File 'lib/ruby-vibe/bot.rb', line 51

def send_message(opts = {})
  opts.merge!(type: 'text') unless opts[:type]

  viberize(URL::SEND_MESSAGE, opts)
end

#set_webhook(opts = {}) ⇒ Object



81
82
83
# File 'lib/ruby-vibe/bot.rb', line 81

def set_webhook(opts = {})
  viberize(URL::SET_WEBHOOK, opts)
end