Class: Viberroo::Bot
- Inherits:
-
Object
- Object
- Viberroo::Bot
- Defined in:
- lib/viberroo/bot.rb
Instance Method Summary collapse
- #broadcast(message:, to:) ⇒ Object
- #broadcast!(message:, to:) ⇒ Object
- #get_account_info ⇒ Object
- #get_account_info! ⇒ Object
- #get_online(ids:) ⇒ Object
- #get_online!(ids:) ⇒ Object
- #get_user_details(id:) ⇒ Object
- #get_user_details!(id:) ⇒ Object
-
#initialize(token: nil, callback: nil) ⇒ Bot
constructor
A new instance of Bot.
- #remove_webhook ⇒ Object
- #remove_webhook! ⇒ Object
- #send(message:, keyboard: {}) ⇒ Object
- #send!(message:, keyboard: {}) ⇒ Object
- #set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
- #set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
Constructor Details
#initialize(token: nil, callback: nil) ⇒ Bot
Returns a new instance of Bot.
3 4 5 6 7 8 9 10 11 |
# File 'lib/viberroo/bot.rb', line 3 def initialize(token: nil, callback: nil) Viberroo.configure @headers = { 'X-Viber-Auth-Token': token || Viberroo.config.auth_token, 'Content-Type': 'application/json' } @callback = callback end |
Instance Method Details
#broadcast(message:, to:) ⇒ Object
40 41 42 |
# File 'lib/viberroo/bot.rb', line 40 def broadcast(message:, to:) request(URL::BROADCAST_MESSAGE, .merge(broadcast_list: to)) end |
#broadcast!(message:, to:) ⇒ Object
44 45 46 |
# File 'lib/viberroo/bot.rb', line 44 def broadcast!(message:, to:) parse broadcast(message: , to: to) end |
#get_account_info ⇒ Object
48 49 50 |
# File 'lib/viberroo/bot.rb', line 48 def get_account_info request(URL::GET_ACCOUNT_INFO) end |
#get_account_info! ⇒ Object
52 53 54 |
# File 'lib/viberroo/bot.rb', line 52 def get_account_info! parse get_account_info end |
#get_online(ids:) ⇒ Object
64 65 66 |
# File 'lib/viberroo/bot.rb', line 64 def get_online(ids:) request(URL::GET_ONLINE, ids: ids) end |
#get_online!(ids:) ⇒ Object
68 69 70 |
# File 'lib/viberroo/bot.rb', line 68 def get_online!(ids:) parse get_online(ids: ids) end |
#get_user_details(id:) ⇒ Object
56 57 58 |
# File 'lib/viberroo/bot.rb', line 56 def get_user_details(id:) request(URL::GET_USER_DETAILS, id: id) end |
#get_user_details!(id:) ⇒ Object
60 61 62 |
# File 'lib/viberroo/bot.rb', line 60 def get_user_details!(id:) parse get_user_details(id: id) end |
#remove_webhook ⇒ Object
23 24 25 |
# File 'lib/viberroo/bot.rb', line 23 def remove_webhook request(URL::WEBHOOK, url: '') end |
#remove_webhook! ⇒ Object
27 28 29 |
# File 'lib/viberroo/bot.rb', line 27 def remove_webhook! parse remove_webhook end |
#send(message:, keyboard: {}) ⇒ Object
31 32 33 34 |
# File 'lib/viberroo/bot.rb', line 31 def send(message:, keyboard: {}) request(URL::MESSAGE, { receiver: @callback&.user_id }.merge().merge(keyboard)) end |
#send!(message:, keyboard: {}) ⇒ Object
36 37 38 |
# File 'lib/viberroo/bot.rb', line 36 def send!(message:, keyboard: {}) parse self.send(message: , keyboard: keyboard) end |
#set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
13 14 15 16 |
# File 'lib/viberroo/bot.rb', line 13 def set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) request(URL::WEBHOOK, url: url, event_types: event_types, send_name: send_name, send_photo: send_photo) end |
#set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
18 19 20 21 |
# File 'lib/viberroo/bot.rb', line 18 def set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil) parse set_webhook(url: url, event_types: event_types, send_name: send_name, send_photo: send_photo) end |