Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cs-chatbots/router-masterbot-tools

Package Overview
Dependencies
Maintainers
4
Versions
434
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cs-chatbots/router-masterbot-tools - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

2

package.json
{
"name": "@cs-chatbots/router-masterbot-tools",
"version": "0.1.7",
"version": "0.2.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,3 +18,3 @@ 'use strict';

/**
* @param {Object} [stateStorage] - chatbot state storage
* @param {object} [stateStorage] - chatbot state storage
*/

@@ -27,8 +27,7 @@ constructor (stateStorage) {

/**
* @param {Object} message - the messaging event object
* @param {object} message - the messaging event object
* @param {string} pageId - id of page (channel), where the event occured
* @param {Sender} messageSender - an instance of Sender class, which allows to send responses
* @returns {Object} - status 200 will stop the dispatching and will be returned
* @returns {object} - status 200 will stop the dispatching and will be returned
*/
async processMessage (message, pageId, messageSender) {
async processMessage (message, pageId) {
// Process just pure sharedContext messages

@@ -40,20 +39,23 @@ if (message

const { sender, recipient, sharedContext } = message;
const senderId = sender.id === pageId ? recipient.id : sender.id;
const state = await this.stateStorage.getState(senderId, pageId);
const { sender, recipient, sharedContext } = message;
const senderId = sender.id === pageId ? recipient.id : sender.id;
const state = await this.stateStorage.getState(senderId, pageId);
if (state) {
if (state) {
const newState = {
...state,
state: {
...state.state,
const newState = {
...state,
state: {
...state.state,
sharedContext: this._getMoreRecentSharedContex(
state.state.sharedContext,
sharedContext
}
};
)
}
};
await this.stateStorage.saveState(newState);
await this.stateStorage.saveState(newState);
return { status: 200 };
}
return { status: 200 };
}
}

@@ -82,6 +84,12 @@

if (req.data.sharedContext) {
req.sharedContext = req.data.sharedContext;
req.sharedContext = this._getMoreRecentSharedContex(
req.sharedContext,
req.data.sharedContext
);
res.setState({ sharedContext: req.sharedContext });
} else {
req.sharedContext = req.state.sharedContext || { };
req.sharedContext = this._getMoreRecentSharedContex(
req.sharedContext,
req.state.sharedContext
);
}

@@ -132,4 +140,17 @@ }

}
/**
* @param {object} orig - Original sharedContext
* @param {object} candid - Candidate to orginal sharedContext
* @returns {object}
*/
_getMoreRecentSharedContex (orig = {}, candid = {}) {
if (orig.timestamp && candid.timestamp) {
return candid.timestamp > orig.timestamp ? candid : orig;
}
return candid;
}
}
module.exports = { SharedContextPlugin };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc