> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# IStore

> Interface exported by @botmesh/core.

Defined in: [core/provider.ts:1500](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1500)

Persistence contract of the bot: message log, chats, contacts, flow checkpoints,
AI history, delivery cursors and (optionally) `ctx.user` data. [MemoryStore](https://botmesh.afaya.com.co/api/core/classes/MemoryStore.md) is the
reference implementation; `@botmesh/sqlite-store` and `@botmesh/redis-store` provide durable ones.
Pass a store as [BotConfig.store](https://botmesh.afaya.com.co/api/core/interfaces/BotConfig.md#store).

## Methods

### saveMessage()

```ts theme={null}
saveMessage(msg): Promise<void>;
```

Defined in: [core/provider.ts:1501](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1501)

#### Parameters

| Parameter | Type |
| - | - |
| `msg` | [`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage) |

#### Returns

`Promise`\<`void`>

***

### getMessage()

```ts theme={null}
getMessage(ref): Promise<StoredMessage | undefined>;
```

Defined in: [core/provider.ts:1502](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1502)

#### Parameters

| Parameter | Type |
| - | - |
| `ref` | [`MessageRef`](https://botmesh.afaya.com.co/api/core/interfaces/MessageRef) |

#### Returns

`Promise`\<[`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage) | `undefined`>

***

### getMessagesByChat()

```ts theme={null}
getMessagesByChat(chatId, limit?): Promise<StoredMessage[]>;
```

Defined in: [core/provider.ts:1503](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1503)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |
| `limit?` | `number` |

#### Returns

`Promise`\<[`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage)\[]>

***

### deleteMessage()

```ts theme={null}
deleteMessage(ref): Promise<void>;
```

Defined in: [core/provider.ts:1504](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1504)

#### Parameters

| Parameter | Type |
| - | - |
| `ref` | [`MessageRef`](https://botmesh.afaya.com.co/api/core/interfaces/MessageRef) |

#### Returns

`Promise`\<`void`>

***

### upsertChat()

```ts theme={null}
upsertChat(chat): Promise<void>;
```

Defined in: [core/provider.ts:1510](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1510)

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

| Parameter | Type |
| - | - |
| `chat` | [`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat) |

#### Returns

`Promise`\<`void`>

***

### getChat()

```ts theme={null}
getChat(chatId): Promise<StoredChat | undefined>;
```

Defined in: [core/provider.ts:1511](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1511)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |

#### Returns

`Promise`\<[`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat) | `undefined`>

***

### listChats()

```ts theme={null}
listChats(): Promise<StoredChat[]>;
```

Defined in: [core/provider.ts:1512](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1512)

#### Returns

`Promise`\<[`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat)\[]>

***

### deleteChat()

```ts theme={null}
deleteChat(chatId): Promise<void>;
```

Defined in: [core/provider.ts:1513](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1513)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |

#### Returns

`Promise`\<`void`>

***

### upsertContact()

```ts theme={null}
upsertContact(contact): Promise<void>;
```

Defined in: [core/provider.ts:1516](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1516)

Shallow-merge `contact` onto the stored record; same `undefined` = unset rule as [upsertChat](#upsertchat).

#### Parameters

| Parameter | Type |
| - | - |
| `contact` | [`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact) |

#### Returns

`Promise`\<`void`>

***

### getContact()

```ts theme={null}
getContact(userId): Promise<StoredContact | undefined>;
```

Defined in: [core/provider.ts:1517](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1517)

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |

#### Returns

`Promise`\<[`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact) | `undefined`>

***

### listContacts()

```ts theme={null}
listContacts(): Promise<StoredContact[]>;
```

Defined in: [core/provider.ts:1518](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1518)

#### Returns

`Promise`\<[`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact)\[]>

***

### deleteContact()

```ts theme={null}
deleteContact(userId): Promise<void>;
```

Defined in: [core/provider.ts:1519](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1519)

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |

#### Returns

`Promise`\<`void`>

***

### getCursor()?

```ts theme={null}
getCursor?(key): Promise<string | undefined>;
```

Defined in: [core/provider.ts:1522](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1522)

Delivery cursor for long-poll/webhook transports (Telegram update\_id).

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`string` | `undefined`>

***

### setCursor()?

```ts theme={null}
setCursor?(key, value): Promise<void>;
```

Defined in: [core/provider.ts:1523](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1523)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `value` | `string` |

#### Returns

`Promise`\<`void`>

***

### getConversation()

```ts theme={null}
getConversation(key): Promise<AIMessage[] | undefined>;
```

Defined in: [core/provider.ts:1526](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1526)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<[`AIMessage`](https://botmesh.afaya.com.co/api/core/interfaces/AIMessage)\[] | `undefined`>

***

### setConversation()

```ts theme={null}
setConversation(key, messages): Promise<void>;
```

Defined in: [core/provider.ts:1527](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1527)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `messages` | [`AIMessage`](https://botmesh.afaya.com.co/api/core/interfaces/AIMessage)\[] |

#### Returns

`Promise`\<`void`>

***

### clearConversation()

```ts theme={null}
clearConversation(key): Promise<void>;
```

Defined in: [core/provider.ts:1528](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1528)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`void`>

***

### getCheckpoint()

```ts theme={null}
getCheckpoint(key): Promise<FlowCheckpoint | undefined>;
```

Defined in: [core/provider.ts:1530](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1530)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<[`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) | `undefined`>

***

### setCheckpoint()

```ts theme={null}
setCheckpoint(key, cp): Promise<void>;
```

Defined in: [core/provider.ts:1531](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1531)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `cp` | [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) |

#### Returns

`Promise`\<`void`>

***

### clearCheckpoint()

```ts theme={null}
clearCheckpoint(key): Promise<void>;
```

Defined in: [core/provider.ts:1532](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1532)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`void`>

***

### listCheckpoints()

```ts theme={null}
listCheckpoints(): Promise<[string, FlowCheckpoint][]>;
```

Defined in: [core/provider.ts:1533](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1533)

#### Returns

`Promise`\<\[`string`, [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint)]\[]>

***

### setCheckpointIf()?

```ts theme={null}
setCheckpointIf?(
   key, 
   cp, 
   expectedRevision
): Promise<boolean>;
```

Defined in: [core/provider.ts:1544](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1544)

Compare-and-set checkpoint write (multi-replica coordination). Succeeds (resolves
`true`) only when the stored row's [FlowCheckpoint.revision](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint.md#revision) equals
`expectedRevision`, where `0` means "no row, or a row without `revision`"; otherwise
the row is left untouched and it resolves `false`. ONE atomic statement per store
(never a read-modify-write), so two replicas racing on one key see exactly one winner.
`expectedRevision` is a non-negative integer (`RangeError` otherwise). Optional: a
store without it keeps the local-fence behaviour; all six built-in stores implement it
and pass the shared conformance block (`test-utils/store-conformance.ts`).

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `cp` | [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) |
| `expectedRevision` | `number` |

#### Returns

`Promise`\<`boolean`>

***

### clearCheckpointIf()?

```ts theme={null}
clearCheckpointIf?(key, expectedRevision): Promise<boolean>;
```

Defined in: [core/provider.ts:1550](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1550)

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](#setcheckpointif).

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `expectedRevision` | `number` |

#### Returns

`Promise`\<`boolean`>

***

### getUserData()?

```ts theme={null}
getUserData?(
   userId, 
   namespace, 
   key
): Promise<UserDataEntry | undefined>;
```

Defined in: [core/provider.ts:1563](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1563)

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

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace` | `string` |
| `key` | `string` |

#### Returns

`Promise`\<[`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry) | `undefined`>

***

### setUserData()?

```ts theme={null}
setUserData?(entry): Promise<void>;
```

Defined in: [core/provider.ts:1569](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1569)

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

| Parameter | Type |
| - | - |
| `entry` | [`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry) |

#### Returns

`Promise`\<`void`>

***

### deleteUserData()?

```ts theme={null}
deleteUserData?(
   userId, 
   namespace?, 
   key?
): Promise<void>;
```

Defined in: [core/provider.ts:1575](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1575)

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

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace?` | `string` |
| `key?` | `string` |

#### Returns

`Promise`\<`void`>

***

### listUserData()?

```ts theme={null}
listUserData?(userId, namespace?): Promise<UserDataEntry[]>;
```

Defined in: [core/provider.ts:1577](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1577)

Live (non-expired) entries of a user — all namespaces, or just `namespace`. Order unspecified.

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace?` | `string` |

#### Returns

`Promise`\<[`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry)\[]>

***

### purgeExpiredUserData()?

```ts theme={null}
purgeExpiredUserData?(now?): Promise<number>;
```

Defined in: [core/provider.ts:1583](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1583)

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

| Parameter | Type |
| - | - |
| `now?` | `number` |

#### Returns

`Promise`\<`number`>

***

### start()

```ts theme={null}
start(): Promise<void>;
```

Defined in: [core/provider.ts:1585](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1585)

#### Returns

`Promise`\<`void`>

***

### stop()

```ts theme={null}
stop(): Promise<void>;
```

Defined in: [core/provider.ts:1586](https://github.com/andresayac/botmesh/blob/main/packages/core/src/core/provider.ts#L1586)

#### Returns

`Promise`\<`void`>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.