Module: YATelegramBot::Base
- Includes:
- TelegramAPI
- Defined in:
- lib/ya_telegram_bot/base.rb
Overview
extend your class with this module to use API. Or include it if you want to use in instances
Instance Method Summary collapse
- #me ⇒ Object
-
#send_photo(params = {}) ⇒ Object
send photo message to user.
-
#send_text(params = {}) ⇒ Object
send text message to user.
- #token(value) ⇒ Object
-
#updates ⇒ Object
loads last updates.
Instance Method Details
#me ⇒ Object
22 23 24 |
# File 'lib/ya_telegram_bot/base.rb', line 22 def me send_api_request 'getMe' end |
#send_photo(params = {}) ⇒ Object
send photo message to user.
required params:
-
:chat [Fixnum] id of chat
-
:file [File] your photo
additional params:
-
:caption [String] caption for your photo
-
:reply_to [Fixnum] id of message you reply
67 68 69 70 71 72 |
# File 'lib/ya_telegram_bot/base.rb', line 67 def send_photo(params = {}) response = send_api_request 'sendPhoto', params_for_sending_photo(params) response['ok'] && Message.new(response['result'], self) end |
#send_text(params = {}) ⇒ Object
send text message to user.
required params:
-
:chat - id of chat
-
:text - your message
additional params:
-
:markdown [Boolean] use telegram markdown
-
:reply_to [Integer] id of message you reply
50 51 52 53 54 |
# File 'lib/ya_telegram_bot/base.rb', line 50 def send_text(params = {}) response = send_api_request 'sendMessage', params_for_sending_text(params) response['ok'] && Message.new(response['result'], self) end |
#token(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/ya_telegram_bot/base.rb', line 16 def token(value) @token = value @api_request_prefix = "bot#{@token}" @last_update_id = -1 # hmmm end |
#updates ⇒ Object
loads last updates. Note than after each #updates your @last_update_id will be changed so if you use it twice you won’t get same result
31 32 33 34 35 36 37 |
# File 'lib/ya_telegram_bot/base.rb', line 31 def updates updates = send_api_request 'getUpdates', offset: @last_update_id + 1 fail ResponseIsNotOk unless updates['ok'] @last_update_id = updates['result'].last['update_id'] unless updates['result'].empty? updates['result'].map { |u| Message.new(u['message'], self) } end |