feat: communication event hooks (on_received, on_sent) #232
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Competitor
Kind/Documentation
Kind/Enhancement
Kind/Epic
Kind/Feature
Kind/Security
Kind/Story
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Scope/Core
Scope/Cross-Plugin
Scope/Plugin-System
Scope/Single-Plugin
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ultanio/cobot!232
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/communication-events"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add two event extension points to the communication plugin:
communication.on_received— fires for each message after pollingcommunication.on_sent— fires after a message is successfully sentWhy
Observer plugins (archival, logging, analytics) need to capture message flow regardless of channel type. Currently the only way is to hook into channel-specific extension points (e.g.
telegram.on_message), which couples observers to specific channels.These events fire at the communication layer, so any plugin implementing them sees messages from all channels.
Changes
cobot/plugins/communication/plugin.py:communication.on_receivedandcommunication.on_senttoextension_pointspoll()fireson_receivedfor each polled messagesend()fireson_sentafter successful send_notify()helper for dispatching to implementersScope
Single plugin change (communication only). No breaking changes — existing implementations are unaffected.
Related
telegram.on_message🦊 PR Review: #232 — feat: communication event hooks
Summary
Adds
communication.on_receivedandcommunication.on_sentevent extension points to the communication plugin, enabling observer plugins to capture message flow across all channels.Checklist (Plugin Design Guide)
<plugin_id>.<hook_name>naming conventionos.environreads_notifyuses_registry.get_implementations()which is the standard patternFindings
🟢 Clean extension point design — New hooks follow the established
call_extension/implementspattern. Observer plugins can simply declareimplements: {"communication.on_received": "my_handler"}and they're wired in automatically.🟢 No breaking changes — Existing implementations are unaffected. The new extension points are purely additive.
🟢 All checks pass — ruff check ✅, ruff format ✅, 1004 tests pass ✅
🟡 Minor: Untyped
messageparameter in_notify()— Themessageparameter is typed as baremessagewithout a type hint. Considermessage: IncomingMessage | OutgoingMessage(orUnion[...]) for clarity and IDE support.🟡 Minor: No tests for the new hooks — While the existing test suite passes, there are no tests verifying that
on_receivedfires duringpoll()oron_sentfires duringsend(). Consider adding a test with a mock implementer.Verdict: Approve ✅
Clean, minimal, well-scoped change that follows the plugin design guide. The two minor items (typing, tests) are nice-to-haves and don't block merge.
🦊 PR Review — #232: feat: communication event hooks
Verdict: ✅ Approve
Clean, well-scoped addition of observer event hooks to the communication plugin.
Findings
🟢 Good: Clean abstraction —
_notify()helper follows existing patterns (send,typing) with proper error handling per implementer.🟢 Good: Event semantics —
on_receivedfires after poll (sorted),on_sentfires only on success. Both are correct.🟢 Good: Test coverage — 3 new tests cover: on_received fires during poll, on_sent fires on success, on_sent does NOT fire on failure.
🟡 Minor:
Unionimport — TheUnionimport is added butUnion["IncomingMessage", "OutgoingMessage"]could useIncomingMessage | OutgoingMessage(Python 3.10+ syntax) since the codebase likely targets 3.10+. Not blocking.🟡 Minor: Pre-existing warnings — Tests emit
RuntimeWarning: coroutine CommunicationPlugin.start was never awaited— this is pre-existing (not introduced by this PR) but worth a follow-up cleanup.Labels
Automated review by Doxios 🦊
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.