Package Exports
- conv-context
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (conv-context) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Conversation Context
A simple class that helps to handle bot conversation context.
Getting started
const Context = require('conv-context');
const context = new Context(contextData, flow);
Resolve context from contextData
// resolver - optional resolver function
const resolvedContext = await context.resolve(resolver=defaultResolver);
Default resolver
async function defaultResolver (output, config) {
const selectStyle = output.selectStyle;
switch (selectStyle) {
case 'inherited':
const from = _.get(output, 'value.from', 'last');
return this.get(from);
case 'step':
return this.getStepContext(output.value.stepId);
case 'dataOut':
return await this.flow.mergeFields[output.value.name].get();
case 'pick':
return output.value.pickValue;
default:
return output.value;
}
}
Custom resolver
const resolver = async function (output, config) {
// your code here
// ...
};
Get context data
// get context for the 'name' entity
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
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);