Route the Telegram adapter through a telegram::TGBot when given - #23
Merged
Merged
Conversation
chat_telegram() takes a bot = telegram::TGBot from the suggested telegram package (CRAN 0.7.1). Requests then go through the class's public req(method, body), so its proxy settings apply and the token can stay private to the object; attachments are fetched from the URL its getFile() returns when called without a destfile. Only the transport is borrowed. The class's own verbs would degrade the adapter: getUpdates() can neither long-poll nor choose update kinds, parsed_content() flattens updates into data frames, getMe() prints, getFile() answers NULL where the Bot API refused, and there are no edit, reaction, chat or leave methods. The direct httr layer stays the default and now shares its response parsing with the TGBot one. The .download seam takes (file_id, file_path, dest) so both layers fit behind it. Bindings on a TGBot are locked, so behavior is tested on a stand-in with the two members the adapter uses; the real class's req() and getFile() signatures are pinned when telegram is installed.
CI installs none of the suggested packages, so chat_telegram()'s httr check fires before its token check there and the no-token assertion saw the wrong message. With both seams supplied the constructor gets past httr and the test exercises what it names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
chat_telegram()takesbot = telegram::TGBotfrom the CRANtelegrampackage (0.7.1, March 2025). Requests then go through the class's publicreq(method, body), so its proxy settings apply and the token can stay private to the object; attachments are fetched from the URL itsgetFile()returns when called without a destfile.Only the transport is borrowed. Delegating the verbs themselves would degrade the adapter:
getUpdates(offset, limit)has notimeoutorallowed_updates, so no long polling and no reaction events.parsed_content()runsjsonlite::fromJSON()with default simplification, turning updates into data frames.getMe()prints to stdout;getFile()answersNULLwhere the Bot API refused.sendMessage()has nomessage_thread_idorreply_parameters.api_urlis ignored with a bot.The direct httr layer stays the default and now shares its response parsing with the TGBot one.
telegramjoins Suggests. The.downloadseam takes(file_id, file_path, dest)so both layers fit behind it.Tests: a TGBot's bindings are locked, so behavior runs on a stand-in with the two members the adapter uses (wire form reaching
req(), uploads asform_file, refusals through the body, non-JSON bodies, the download URL path and itsNULLcase). The real class'sreq()andgetFile()signatures are pinned whentelegramis installed; CI does not install it, so those pins run locally. 1414 assertions pass with the package present and the guards skip cleanly without it; R CMD check shows only the new-submission NOTE.