MessagingHubModule · library/messaging/src/repos/messaging-bindings.ts:121

MessagingBindingsRepo

component

No JSDoc comment in source yet.

API

@Component()
export class MessagingBindingsRepo implements MessagingBindings {
  @Use() private readonly db!: Db;
  find(sessionId: string, channel: string): MessagingBindingRow | null;
  findEnabled(sessionId: string): MessagingBindingRow | null;
  listForSession(sessionId: string): MessagingBindingRow[];
  findEnabledByAccount(channel: string, accountId: string): MessagingBindingRow | null;
  listAll(): MessagingBindingRow[];
  upsert(args: {
    sessionId: string;
    channel: string;
    accountId: string;
    config: Record<string, unknown>;
    linePerMessage?: boolean;
    finalReplyOnly?: boolean;
    renderMarkdown?: boolean;
  }): MessagingBindingRow;
  setEnabled(sessionId: string, channel: string, enabled: boolean): void;
  recordChat(sessionId: string, channel: string, chatId: string, isDirect: boolean): void;
  recordInboundWatermark(sessionId: string, channel: string, messageId: string | null): void;
  delete(sessionId: string, channel: string): void;
  deleteSession(sessionId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (11)

find

find(sessionId: string, channel: string): MessagingBindingRow | null

The Session's saved config of ONE channel (null when that channel is not configured).

@paramsessionIdstring
@paramchannelstring
@returnsMessagingBindingRow | null

findEnabled

findEnabled(sessionId: string): MessagingBindingRow | null

The Session's enabled binding — at most one exists (route-enforced); null when all are dark.

@paramsessionIdstring
@returnsMessagingBindingRow | null

listForSession

listForSession(sessionId: string): MessagingBindingRow[]

Every channel config the Session has saved, in stable channel order.

@paramsessionIdstring
@returnsMessagingBindingRow[]

findEnabledByAccount

findEnabledByAccount(channel: string, accountId: string): MessagingBindingRow | null

Whichever binding currently holds this account's connection — null while every Session that saved the account keeps it dark. At most one row can match, for the same reason findEnabled is at-most-one: the state route refuses the second enable, and its guard-then-flip runs in one synchronous block, so two requests cannot interleave between the check and the write.

@paramchannelstring
@paramaccountIdstring
@returnsMessagingBindingRow | null

listAll

listAll(): MessagingBindingRow[]
@returnsMessagingBindingRow[]

upsert

upsert(args: { sessionId: string; channel: string; accountId: string; config: Record<string, unknown>; linePerMessage?: boolean; finalReplyOnly?: boolean; renderMarkdown?: boolean; }): MessagingBindingRow

Create or replace the Session's config for one channel — credentials/config only: enabled is intent state the state toggle owns, so an insert starts disabled and an update keeps the stored value. linePerMessage, finalReplyOnly and renderMarkdown are ordinary saved fields this write does own, and an omitted one keeps the stored value (a fresh row starts with the first two off and the third ON, matching the column defaults). It cannot fail on another Session: the same account saved elsewhere is none of this write's business, since only enabling is exclusive. Re-saving a Session's own binding keeps its last-chat memory, so a settings edit never loses the reply target — unless the account changed, whose chats are unrelated: the remembered chat is dropped so replies can never land in the old bot's conversation.

@paramargs{ sessionId: string; channel: string; accountId: string; config: Record<string, unknown>; linePerMessage?: boolean; finalReplyOnly?: boolean; renderMarkdown?: boolean; }
@returnsMessagingBindingRow

setEnabled

setEnabled(sessionId: string, channel: string, enabled: boolean): void

The state toggle's write: flip one channel's connection intent (the bridge then aligns the live connection).

@paramsessionIdstring
@paramchannelstring
@paramenabledboolean
@returnsvoid

recordChat

recordChat(sessionId: string, channel: string, chatId: string, isDirect: boolean): void

Remember the most recent inbound chat (the reply and test-message target; chats are channel-scoped).

@paramsessionIdstring
@paramchannelstring
@paramchatIdstring
@paramisDirectboolean
@returnsvoid

recordInboundWatermark

recordInboundWatermark(sessionId: string, channel: string, messageId: string | null): void

Advance the bridge's durable redelivery watermark to a message it has FINISHED with. Deliberately its own statement, issued after the work rather than folded into recordChat: a watermark written first would, if the process died before the Task existed, mark as processed a message nothing ever ran — and the seeding in MessagingBridge.connect would then swallow the channel's replay of it.

A null messageId (a channel that mints no message identity) leaves the column alone rather than clearing it: such a message opts out of the dedupe entirely, so it has nothing to say about the last message that did carry one.

@paramsessionIdstring
@paramchannelstring
@parammessageIdstring | null
@returnsvoid

delete

delete(sessionId: string, channel: string): void

Drop one channel's config.

@paramsessionIdstring
@paramchannelstring
@returnsvoid

deleteSession

deleteSession(sessionId: string): void

Drop every channel config of a Session (the session-delete cascade).

@paramsessionIdstring
@returnsvoid