@cs-chatbots/router-masterbot-tools
Advanced tools
Comparing version 0.1.7 to 0.2.0
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1307019
2822
7