0.0.14 • Published 2 years ago

conv-context v0.0.14

Weekly downloads
149
License
ISC
Repository
-
Last release
2 years ago

Conversation Context

A simple class that helps to handle bot conversation context.

Getting started

const Context = require('conv-context');
const context = new Context(contextData, thread);

Resolve context from contextData

// resolver - optional resolver function
const resolvedContext = await context.resolve(resolver=defaultResolver, data);

Custom resolver (binded to the step's 'this')

const resolver = async function (output, store) {
  // your code here
  // ...
};

Get context data

// 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

// 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

// save context data to session and shared (optional) storage
await context.save(shared=true, ttl=null)

helper methods for each storage

// save session data
context.setSession();

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

2 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago