The optional-capability pattern had media and delete but no interactive UX: a channel could ask a human to approve an action through ApprovalRequester, but there was no domain contract for posing a clarifying question or presenting a single-choice picker, and no capability flag a caller could read before attempting one. Add ClarifyRequester and PickerRequester to internal/domain/messaging alongside ApprovalRequester, with Clarify/Picker/Approval flags on AdapterCapabilities and ClarifierOf/PickerOf/ApproverOf lookups that treat the capability as the contract rather than the method set, so a mis-reporting adapter degrades instead of panicking. TextFallback is the shared text degrade: a channel with no native question or selection UI still carries the interaction (numbered prompt, parsed reply) instead of failing or silently dropping it. FormatClarifyText/FormatPickerText/ParsePickerReply hold the rendering and matching logic once. The approval half reuses the existing decision model: Telegram's telegramApprover already renders a native prompt, so it now reports the Approval capability and deliberately does not claim Clarify/Picker it has no native UI for. Gateway re-exports the contract. Red-first: internal/domain/messaging/interactive_test.go drives the test double adapters (native, degrade, mis-reporting, over-claiming) and the text rendering/parsing; telegram/approval_test.go pins the honest capability report.
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
// Package gateway: interactive.go re-exports the adapter interactive-UX
|
|
// contract from internal/domain/messaging so gateway-internal code and
|
|
// channel tests can name it without qualifying the domain package.
|
|
//
|
|
// The contract is the interactive counterpart of the media/delete
|
|
// capabilities in adapter_capabilities.go: clarify and picker are optional
|
|
// interfaces an adapter type-asserts through ClarifierOf/PickerOf, and
|
|
// approval reuses the existing ApprovalRequester flow rather than a second
|
|
// decision model. TextFallback is the shared text degrade for an adapter
|
|
// with no native question or selection UI.
|
|
|
|
package gateway
|
|
|
|
import "github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
|
|
// Interactive request and answer types.
|
|
type (
|
|
InteractiveChoice = messaging.InteractiveChoice
|
|
ClarifyRequest = messaging.ClarifyRequest
|
|
PickerRequest = messaging.PickerRequest
|
|
)
|
|
|
|
// Optional interactive interfaces an adapter may implement.
|
|
type (
|
|
ClarifyRequester = messaging.ClarifyRequester
|
|
PickerRequester = messaging.PickerRequester
|
|
)
|
|
|
|
// TextFallback is the shared text-based degrade.
|
|
type TextFallback = messaging.TextFallback
|
|
|
|
// Re-exported sentinel errors.
|
|
var (
|
|
ErrNoPickerOptions = messaging.ErrNoPickerOptions
|
|
ErrEmptyReply = messaging.ErrEmptyReply
|
|
ErrTextFallbackNotConfigured = messaging.ErrTextFallbackNotConfigured
|
|
)
|
|
|
|
// Re-exported capability lookups.
|
|
var (
|
|
ClarifierOf = messaging.ClarifierOf
|
|
PickerOf = messaging.PickerOf
|
|
ApproverOf = messaging.ApproverOf
|
|
)
|
|
|
|
// Re-exported text rendering and parsing helpers.
|
|
var (
|
|
FormatClarifyText = messaging.FormatClarifyText
|
|
FormatPickerText = messaging.FormatPickerText
|
|
ParsePickerReply = messaging.ParsePickerReply
|
|
)
|