Class: TelegramBot

Inherits:
Object
  • Object
show all
Includes:
EventHandler, Request, RequestMethods
Defined in:
lib/telegram_bot.rb,
lib/telegram_bot/handler.rb,
lib/telegram_bot/matcher.rb,
lib/telegram_bot/request.rb,
lib/telegram_bot/version.rb,
lib/telegram_bot/message_proxy.rb,
lib/telegram_bot/poll_listener.rb,
lib/telegram_bot/request_methods.rb,
lib/telegram_bot/auto_from_methods.rb

Defined Under Namespace

Modules: AutoFromMethods, EventHandler, Request, RequestMethods, ShorthandMethods Classes: AnythingMatcher, Audio, Chat, CommandMatcher, Contact, Date, Document, FallbackMatcher, ForceReply, GroupChat, Location, Matcher, Message, MessageProxy, PhotoSize, PollListener, ReplyKeyboardHide, ReplyKeyboardMarkup, Sticker, TextMatcher, Update, User, Video

Constant Summary collapse

VERSION =
"0.1.7"

Constants included from RequestMethods

RequestMethods::CHAT_ACTIONS, RequestMethods::METHODS

Constants included from Request

Request::API_BASE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestMethods

#forward_message, #get_me, #get_updates, #send_chat_action, #send_message

Methods included from Request

included, #request

Methods included from EventHandler

#handle, included, #on

Constructor Details

#initialize(history: 50) ⇒ TelegramBot

Returns a new instance of TelegramBot.



17
18
19
20
21
# File 'lib/telegram_bot.rb', line 17

def initialize(history: 50)
  @history = []
  @history_length = 50
  @listener = nil
end

Instance Attribute Details

#historyObject

Returns the value of attribute history.



15
16
17
# File 'lib/telegram_bot.rb', line 15

def history
  @history
end

Instance Method Details

#append_history(message) ⇒ Object



32
33
34
35
# File 'lib/telegram_bot.rb', line 32

def append_history(message)
  @history << message
  @history = @history.last(@history_length || 0)
end

#listen(method: :poll, interval: 5, path: '/hook') ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/telegram_bot.rb', line 23

def listen(method: :poll, interval: 5, path: '/hook')
  case method
  when :poll
    @listener = PollListener.new(self, interval)
  when :webhook
    warn 'not implemented'
  end
end

#start!Object



37
38
39
# File 'lib/telegram_bot.rb', line 37

def start!
  @listener.start!
end

#stop!Object



41
42
43
# File 'lib/telegram_bot.rb', line 41

def stop!
  @listener.stop!
end