Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to read updates in listening mode #315

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/telegram/bot/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ def fetch_updates
end

def handle_update(update)
@options[:offset] = update.update_id.next
message = update.current_message
log_incoming_message(message)
options[:offset] = update.update_id.next

message
if options[:listen_update_mode]
log_incoming_update(update)

update
else
message = update.current_message
log_incoming_message(message)

message
end
end

private
Expand All @@ -64,6 +71,12 @@ def log_incoming_message(message)
format('Incoming message: text="%<message>s" uid=%<uid>s', message: message, uid: uid)
)
end

def log_incoming_update(update)
logger.info(
format('Incoming update: uid=%<uid>s', uid: update.update_id)
)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/telegram/bot/exceptions/response_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ResponseError < Base
def initialize(response:)
@response = response

super "Telegram API has returned the error. (#{data.map { |k, v| %(#{k}: #{v.inspect}) }.join(', ')})"
super("Telegram API has returned the error. (#{data.map { |k, v| %(#{k}: #{v.inspect}) }.join(', ')})")
end

def error_code
Expand Down