Add a Telegram adapter - #20
Merged
Merged
Conversation
chat_telegram() puts the Bot API behind the contract, with HTTP delegated to the suggested httr package. getUpdates long polling is the poll, with one update offset as the cursor across every chat the bot is in; the first poll returns whatever Telegram is still holding, which is the mail that arrived while the bot was down rather than history. Sends render markdown to Telegram HTML, carry thread and reply targets, send each file as its own message ahead of the text, and honour notify = FALSE. Edits, emoji reactions and reaction events, typing, chat info, leaving, getMe identity, setMyName, @username addressing, and attachment fetch through getFile are all wired. Capabilities are honest about the Bot API: no history, member list, chat list, read markers, joining, or creating. Reaction events reach a bot in a group only where it is an administrator. Ids are formatted with %.0f rather than as.character(): R writes the double 100000 as "1e+05", and every id Telegram sends is a number. Every verb is exercised through a .api seam asserting on the wire shape each method receives, and httr formals are pinned for drift.
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.
Fourth adapter, the one DESIGN.md calls "nearly free once the poll contract exists".
chat_telegram()puts the Bot API behind the contract with HTTP delegated to httr, which was already in Suggests, so the dependency footprint does not change.allowed_updatesasks for messages, channel posts, and reaction events; edits are not requested.threadasmessage_thread_idandreply_toasreply_parameters, send each file as its ownsendDocumentahead of the text so ids come back in the order Matrix uses, and honournotify = FALSE. A suppliedrichfragment is sent as HTML.chat_reactionrecords (additions only; a removal has no shape in the contract), typing,getChatinfo,leaveChat,getMeidentity,setMyName, and attachment fetch throughgetFileare wired.chat_addressed()reads@usernamefrom the body, treats a private chat and a reply to the bot as addressed, and still honours declaredtext_mentionentities.sprintf("%.0f")rather thanas.character(): R writes the double 100000 as "1e+05", and every id Telegram sends is a number to its JSON parser.Tests: every verb runs through a
.apiseam that asserts on the wire shape each Bot API method receives (form-encoded, NULLs dropped, logicals lowercase), and httr's formals are pinned for drift. The real HTTP layer was probed once against api.telegram.org with a fake token: the 401 surfaces as "Telegram refused getMe: Unauthorized" through the parsed body. 1363 tests pass under R CMD check; the one WARNING (chat_edit()'s undocumentedrich) is pre-existing on main and gets its own PR.