Skip to content

feat: make builders monadic via TelegramEx.Effect#27

Merged
lsdrfrx merged 3 commits into
mainfrom
feature/monadic-builders
Jul 1, 2026
Merged

feat: make builders monadic via TelegramEx.Effect#27
lsdrfrx merged 3 commits into
mainfrom
feature/monadic-builders

Conversation

@lsdrfrx

@lsdrfrx lsdrfrx commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Description

Adds the new TelegramEx.Effect execution model and adapts builders to use it.

Builders now accept either a raw handler context map or an existing TelegramEx.Effect, and return an effect. This keeps the existing pipeline style while allowing builder chains to carry errors instead of raising or
returning early. For example, file-based builders can now preserve file read failures in the effect, and API request failures are also stored in the same flow.

The server no longer needs to know effect internals directly. TelegramEx.Effect.to_result/1 converts an effect back into a normal handler result, and TelegramEx.Server continues to handle FSM transitions, :ok, :pass,
and errors as regular handler outcomes.

A shared TelegramEx.Builder.put_payload/3 helper was added to avoid duplicating payload mutation logic across builders.

How it works now:

  • Builders call Effect.wrap/1, so users can start pipelines with the usual ctx.
  • Payload-only steps use Effect.map_ctx/2.
  • Fallible steps use Effect.then/2.
  • File read failures are stored as {:file, reason}.
  • API failures are stored as effect errors.
  • Server.handle_result/4 calls Effect.to_result/1 and then processes the normalized result.
  • Common payload updates are centralized in TelegramEx.Builder.put_payload/3.

This keeps the public DX close to the old style:

  ctx
  |> Document.path("/tmp/report.pdf")
  |> Document.caption("Report")
  |> Document.send(chat_id)

but the pipeline can now safely carry errors through the builder chain.

Ready Checklist

  • Implementation: code works, types are specified, dialyzer passes
  • Documentation: functions have @doc, README updated if needed
  • Tests: tests added/updated, mix test passes locally

Related Issues

Closes #21, #20

@lsdrfrx lsdrfrx added this to the v1.3.0 milestone Jul 1, 2026
@lsdrfrx lsdrfrx self-assigned this Jul 1, 2026
@lsdrfrx lsdrfrx added the enhancement New feature or request label Jul 1, 2026
@lsdrfrx lsdrfrx merged commit b57e084 into main Jul 1, 2026
1 check passed
@lsdrfrx lsdrfrx deleted the feature/monadic-builders branch July 11, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add monadic behaviour to Builders

1 participant