Skip to content

Route the Telegram adapter through a telegram::TGBot when given - #23

Merged
TroyHernandez merged 3 commits into
mainfrom
telegram-tgbot
Sep 11, 2026
Merged

TroyHernandez merged 3 commits into
mainfrom
telegram-tgbot

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

chat_telegram() takes bot = telegram::TGBot from the CRAN telegram package (0.7.1, March 2025). 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. Delegating the verbs themselves would degrade the adapter:

  • getUpdates(offset, limit) has no timeout or allowed_updates, so no long polling and no reaction events.
  • parsed_content() runs jsonlite::fromJSON() with default simplification, turning updates into data frames.
  • getMe() prints to stdout; getFile() answers NULL where the Bot API refused.
  • No edit, reaction, chat, or leave methods; sendMessage() has no message_thread_id or reply_parameters.
  • The host is hard-coded, so api_url is ignored with a bot.

The direct httr layer stays the default and now shares its response parsing with the TGBot one. telegram joins Suggests. The .download seam 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 as form_file, refusals through the body, non-JSON bodies, the download URL path and its NULL case). The real class's req() and getFile() signatures are pinned when telegram is 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.

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.
@TroyHernandez
TroyHernandez merged commit 5548cba into main Sep 11, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the telegram-tgbot branch September 11, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant