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: {}, response: {}) ⇒ 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: {}, response: {}) ⇒ Bot
4 5 6 7 8 |
# File 'lib/viberroo/bot.rb', line 4 def initialize(token:, callback: {}, response: {}) @headers = { 'X-Viber-Auth-Token': token, 'Content-Type': 'application/json' } @response = response @callback = callback end |
Instance Method Details
#broadcast(message:, to:) ⇒ Object
45 46 47 |
# File 'lib/viberroo/bot.rb', line 45 def broadcast(message:, to:) request(URL::BROADCAST_MESSAGE, .merge(broadcast_list: to)) end |
#broadcast!(message:, to:) ⇒ Object
49 50 51 |
# File 'lib/viberroo/bot.rb', line 49 def broadcast!(message:, to:) parse broadcast(message: , to: to) end |
#get_account_info ⇒ Object
53 54 55 |
# File 'lib/viberroo/bot.rb', line 53 def get_account_info request(URL::GET_ACCOUNT_INFO) end |
#get_account_info! ⇒ Object
57 58 59 |
# File 'lib/viberroo/bot.rb', line 57 def get_account_info! parse get_account_info end |
#get_online(ids:) ⇒ Object
69 70 71 |
# File 'lib/viberroo/bot.rb', line 69 def get_online(ids:) request(URL::GET_ONLINE, ids: ids) end |
#get_online!(ids:) ⇒ Object
73 74 75 |
# File 'lib/viberroo/bot.rb', line 73 def get_online!(ids:) parse get_online(ids: ids) end |
#get_user_details(id:) ⇒ Object
61 62 63 |
# File 'lib/viberroo/bot.rb', line 61 def get_user_details(id:) request(URL::GET_USER_DETAILS, id: id) end |
#get_user_details!(id:) ⇒ Object
65 66 67 |
# File 'lib/viberroo/bot.rb', line 65 def get_user_details!(id:) parse get_user_details(id: id) end |
#remove_webhook ⇒ Object
22 23 24 |
# File 'lib/viberroo/bot.rb', line 22 def remove_webhook request(URL::WEBHOOK, url: '') end |
#remove_webhook! ⇒ Object
26 27 28 |
# File 'lib/viberroo/bot.rb', line 26 def remove_webhook! parse remove_webhook end |
#send(message:, keyboard: {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/viberroo/bot.rb', line 30 def send(message:, keyboard: {}) if @callback.is_a?(Callback) receiver = @callback.user_id elsif @response.is_a?(RecursiveOpenStruct) receiver = @response.user_id end request(URL::MESSAGE, { receiver: receiver }.merge().merge(keyboard)) end |
#send!(message:, keyboard: {}) ⇒ Object
41 42 43 |
# File 'lib/viberroo/bot.rb', line 41 def send!(message:, keyboard: {}) parse self.send(message: , keyboard: keyboard) end |
#set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object
10 11 12 13 14 |
# File 'lib/viberroo/bot.rb', line 10 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
16 17 18 19 20 |
# File 'lib/viberroo/bot.rb', line 16 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 |