# conv-context-next

> Conversation context manager

Latest version **1.0.0** (published 2023-03-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install conv-context-next
pnpm add conv-context-next
yarn add conv-context-next
bun add conv-context-next
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-03-24 |
| First published | 2023-03-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | onereach.user |
| Keywords | bot, context, conversation |

## Links

- npm: https://www.npmjs.com/package/conv-context-next
- npm.io page: https://npm.io/package/conv-context-next

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.19
- [@onereach/time-interpreter](https://npm.io/package/@onereach/time-interpreter.md) ^1.0.27

## Recent versions

- 1.0.0 (latest) — 2023-03-24
- 1.0.1-packagejson4.0 (beta) — 2023-03-24
- 1.0.1-packagejson3.0 — 2023-03-24

## README

# Conversation Context
A simple class that helps to handle bot conversation context.

## Getting started
```javascript
const Context = require('conv-context');
const context = new Context(contextData, thread);
```

## Resolve context from `contextData`
```javascript
// resolver - optional resolver function
const resolvedContext = await context.resolve(resolver=defaultResolver);
```

### Custom resolver (binded to the step's 'this')
```javascript
const resolver = async function (output, store) {
  // your code here
  // ...
};
```

## Get context data
```javascript
// get context for the 'name' entity. The path is also accepted: 'path.to.data'
context.get('name', data, defaultValue);

// get context from step with Id === stepId 
context.getStepContext(stepId)

// find step context by some filter criteria
context.findStepContext(query={})

// find step Id by some filter criteria
context.findStepId(query={})

// get step contexts by some filter criteria
context.filterStepContext(query={})
```

## Set context data
```javascript
// set context for the 'name' entity. The path is also accepted: 'path.to.data'
context.set('name', data);

// set step context
context.setStepContext(data)
```

## Save context in the session and shared storage
```javascript
// save context data to session and shared (optional) storage
await context.save(shared=true, ttl=null)
```

#### helper methods for each storage

```javascript
// save session data
context.setSession();

// save shared session data
await context.setShared(ttl);
```

---
_Source: https://npm.io/package/conv-context-next · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
