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:, 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:, callback: nil) ⇒ Bot
Returns a new instance of Bot.
3 4 5 6 |
# File 'lib/viberroo/bot.rb', line 3 def initialize(token:, callback: nil) @headers = { 'X-Viber-Auth-Token': token, 'Content-Type': 'application/json' } @callback = callback end |
Instance Method Details
#broadcast(message:, to:) ⇒ Object
37 38 39 |
# File 'lib/viberroo/bot.rb', line 37 def broadcast(message:, to:) request(URL::BROADCAST_MESSAGE, .merge(broadcast_list: to)) end |
#broadcast!(message:, to:) ⇒ Object
41 42 43 |
# File 'lib/viberroo/bot.rb', line 41 def broadcast!(message:, to:) parse broadcast(message: , to: to) end |
#get_account_info ⇒ Object
45 46 47 |
# File 'lib/viberroo/bot.rb', line 45 def get_account_info request(URL::GET_ACCOUNT_INFO) end |
#get_account_info! ⇒ Object
49 50 51 |
# File 'lib/viberroo/bot.rb', line 49 def get_account_info! parse get_account_info end |
#get_online(ids:) ⇒ Object
61 62 63 |
# File 'lib/viberroo/bot.rb', line 61 def get_online(ids:) request(URL::GET_ONLINE, ids: ids) end |
#get_online!(ids:) ⇒ Object
65 66 67 |
# File 'lib/viberroo/bot.rb', line 65 def get_online!(ids:) parse get_online(ids: ids) end |
#get_user_details(id:) ⇒ Object
53 54 55 |
# File 'lib/viberroo/bot.rb', line 53 def get_user_details(id:) request(URL::GET_USER_DETAILS, id: id) end |
#get_user_details!(id:) ⇒ Object
57 58 59 |
# File 'lib/viberroo/bot.rb', line 57 def get_user_details!(id:) parse get_user_details(id: id) end |
#remove_webhook ⇒ Object
20 21 22 |
# File 'lib/viberroo/bot.rb', line 20 def remove_webhook request(URL::WEBHOOK, url: '') end |
#remove_webhook! ⇒ Object
24 25 26 |
# File 'lib/viberroo/bot.rb', line 24 def remove_webhook! parse remove_webhook end |
#send(message:, keyboard: {}) ⇒ Object
28 29 30 31 |
# File 'lib/viberroo/bot.rb', line 28 def send(message:, keyboard: {}) request(URL::MESSAGE, { receiver: @callback&.user_id }.merge().merge(keyboard)) end |
#send!(message:, keyboard: {}) ⇒ Object
33 34 35 |
# File 'lib/viberroo/bot.rb', line 33 def send!(message:, keyboard: {}) parse self.send(message: , keyboard: keyboard) end |
#set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/viberroo/bot.rb', line 8 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
14 15 16 17 18 |
# File 'lib/viberroo/bot.rb', line 14 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 |