Skip to main content
Defined in: store/MemoryStore.ts:80 The built-in IStore: everything in RAM, optionally saved to a JSON file on an interval and when the bot stops. It is the default store. It keeps the newest 1000 messages per chat unless maxMessagesPerChat says otherwise. For a database, use @botmesh/sqlite-store or @botmesh/redis-store.

Example

Implements

Constructors

Constructor

Defined in: store/MemoryStore.ts:97

Parameters

Returns

MemoryStore

Methods

start()

Defined in: store/MemoryStore.ts:112

Returns

Promise<void>

Implementation of

IStore.start

stop()

Defined in: store/MemoryStore.ts:134

Returns

Promise<void>

Implementation of

IStore.stop

saveMessage()

Defined in: store/MemoryStore.ts:199

Parameters

Returns

Promise<void>

Implementation of

IStore.saveMessage

getMessage()

Defined in: store/MemoryStore.ts:206

Parameters

Returns

Promise<StoredMessage | undefined>

Implementation of

IStore.getMessage

getMessagesByChat()

Defined in: store/MemoryStore.ts:210

Parameters

Returns

Promise<StoredMessage[]>

Implementation of

IStore.getMessagesByChat

deleteMessage()

Defined in: store/MemoryStore.ts:217

Parameters

Returns

Promise<void>

Implementation of

IStore.deleteMessage

upsertChat()

Defined in: store/MemoryStore.ts:223 Shallow-merge chat onto the stored record. An own field set to undefined UNSETS that field, so a partial upsert must omit what it does not know (the Bot does).

Parameters

Returns

Promise<void>

Implementation of

IStore.upsertChat

getChat()

Defined in: store/MemoryStore.ts:228

Parameters

Returns

Promise<StoredChat | undefined>

Implementation of

IStore.getChat

listChats()

Defined in: store/MemoryStore.ts:232

Returns

Promise<StoredChat[]>

Implementation of

IStore.listChats

deleteChat()

Defined in: store/MemoryStore.ts:236

Parameters

Returns

Promise<void>

Implementation of

IStore.deleteChat

upsertContact()

Defined in: store/MemoryStore.ts:243 Shallow-merge contact onto the stored record; same undefined = unset rule as upsertChat.

Parameters

Returns

Promise<void>

Implementation of

IStore.upsertContact

getContact()

Defined in: store/MemoryStore.ts:248

Parameters

Returns

Promise<StoredContact | undefined>

Implementation of

IStore.getContact

listContacts()

Defined in: store/MemoryStore.ts:252

Returns

Promise<StoredContact[]>

Implementation of

IStore.listContacts

deleteContact()

Defined in: store/MemoryStore.ts:256

Parameters

Returns

Promise<void>

Implementation of

IStore.deleteContact

getCursor()

Defined in: store/MemoryStore.ts:262 Delivery cursor for long-poll/webhook transports (Telegram update_id).

Parameters

Returns

Promise<string | undefined>

Implementation of

IStore.getCursor

setCursor()

Defined in: store/MemoryStore.ts:266

Parameters

Returns

Promise<void>

Implementation of

IStore.setCursor

getCheckpoint()

Defined in: store/MemoryStore.ts:272

Parameters

Returns

Promise<FlowCheckpoint | undefined>

Implementation of

IStore.getCheckpoint

setCheckpoint()

Defined in: store/MemoryStore.ts:276

Parameters

Returns

Promise<void>

Implementation of

IStore.setCheckpoint

clearCheckpoint()

Defined in: store/MemoryStore.ts:280

Parameters

Returns

Promise<void>

Implementation of

IStore.clearCheckpoint

setCheckpointIf()

Defined in: store/MemoryStore.ts:285 Compare-and-set (see IStore.setCheckpointIf): one synchronous step, so concurrent callers see one winner.

Parameters

Returns

Promise<boolean>

Implementation of

IStore.setCheckpointIf

clearCheckpointIf()

Defined in: store/MemoryStore.ts:292 Conditional delete: true when the row is absent, or its revision (0 without one) matched expectedRevision and it was deleted; false when a different revision is stored (the row is left untouched). Same atomicity rule as setCheckpointIf.

Parameters

Returns

Promise<boolean>

Implementation of

IStore.clearCheckpointIf

listCheckpoints()

Defined in: store/MemoryStore.ts:301

Returns

Promise<[string, FlowCheckpoint][]>

Implementation of

IStore.listCheckpoints

getConversation()

Defined in: store/MemoryStore.ts:307

Parameters

Returns

Promise<AIMessage[] | undefined>

Implementation of

IStore.getConversation

setConversation()

Defined in: store/MemoryStore.ts:312

Parameters

Returns

Promise<void>

Implementation of

IStore.setConversation

clearConversation()

Defined in: store/MemoryStore.ts:316

Parameters

Returns

Promise<void>

Implementation of

IStore.clearConversation

getUserData()

Defined in: store/MemoryStore.ts:322 Read one entry. MUST return undefined when the entry is missing OR its expiresAt is <= Date.now() (lazy expiry — expired rows may still exist physically until purged).

Parameters

Returns

Promise<UserDataEntry | undefined>

Implementation of

IStore.getUserData

setUserData()

Defined in: store/MemoryStore.ts:326 Upsert one entry as a SINGLE atomic write that replaces both value and expiresAt (no read-modify-write inside the store). An entry whose expiresAt is already in the past may be dropped instead of written.

Parameters

Returns

Promise<void>

Implementation of

IStore.setUserData

deleteUserData()

Defined in: store/MemoryStore.ts:330 Delete one key (namespace + key), one whole namespace (key omitted) or every namespace of the user (namespace omitted; key is then ignored). Deleting missing data is a no-op.

Parameters

Returns

Promise<void>

Implementation of

IStore.deleteUserData

listUserData()

Defined in: store/MemoryStore.ts:334 Live (non-expired) entries of a user — all namespaces, or just namespace. Order unspecified.

Parameters

Returns

Promise<UserDataEntry[]>

Implementation of

IStore.listUserData

purgeExpiredUserData()

Defined in: store/MemoryStore.ts:338 Physically remove entries whose expiresAt <= now (default Date.now()) across the whole store; resolves with how many were removed. Stores with native expiry (Redis) resolve 0.

Parameters

Returns

Promise<number>

Implementation of

IStore.purgeExpiredUserData

Accessors

durable

Get Signature

Defined in: store/MemoryStore.ts:110 true when this store mirrors itself to a JSON file, so its data (including persistent() flow checkpoints) survives a process restart. false = RAM only.
Returns
boolean