LemonChannels.Adapters.WhatsApp.Transport.MessageBuffer (lemon_channels v0.1.0)

View Source

Message buffering and debounce logic for the WhatsApp transport.

Handles the accumulation of non-command messages within a configurable debounce window so that rapid-fire user messages are coalesced into a single inbound submission.

Functions here operate on the buffers map from GenServer state but do not mutate state directly -- they return the updated buffers (or a full state map update) so the caller can apply it.

Summary

Functions

Drop any pending buffer for the given inbound's scope key (e.g. when a command like /new should flush pending text).

Add an inbound message to the debounce buffer for its scope key.

Collapse the buffered messages into a single inbound and submit it.

Functions

drop_buffer_for(state, inbound)

Drop any pending buffer for the given inbound's scope key (e.g. when a command like /new should flush pending text).

Returns the updated state.

enqueue_buffer(state, inbound)

Add an inbound message to the debounce buffer for its scope key.

Returns the updated state map with buffers modified.

submit_buffer(map, submit_fn)

Collapse the buffered messages into a single inbound and submit it.

This merges multiple message entries into one text block, then delegates to the submit_fn callback (which should be &submit_inbound_now/2).

Returns :ok (the submission side-effect is performed via the callback).