@cs-chatbots/router-masterbot-tools
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "@cs-chatbots/router-masterbot-tools", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
'use strict'; | ||
const PROCESS_EVENTS = [ | ||
'postback', | ||
'referral', | ||
'optin', | ||
'pass_thread_control', | ||
'message', | ||
'request_thread_control', | ||
'take_thread_control', | ||
'read', | ||
'delivery' | ||
]; | ||
class SharedContextPlugin { | ||
/** | ||
* @param {Object} [stateStorage] - chatbot state storage | ||
*/ | ||
constructor (stateStorage) { | ||
this.stateStorage = stateStorage; | ||
} | ||
/** | ||
* @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 | ||
*/ | ||
async processMessage (message, pageId, messageSender) { | ||
// Process just pure sharedContext messages | ||
if (message | ||
&& typeof message === 'object' | ||
&& message.sharedContext | ||
&& !PROCESS_EVENTS.some((e) => typeof message[e] !== 'undefined')) { | ||
const { sender, recipient, sharedContext } = message; | ||
const senderId = sender.id === pageId ? recipient.id : sender.id; | ||
const state = await this.stateStorage.getState(senderId, pageId); | ||
if (state) { | ||
const newState = { | ||
...state, | ||
state: { | ||
...state.state, | ||
sharedContext | ||
} | ||
}; | ||
await this.stateStorage.saveState(newState); | ||
return { status: 200 }; | ||
} | ||
} | ||
return { status: 204 }; | ||
} | ||
/** | ||
* @param {Request} req | ||
@@ -7,0 +63,0 @@ * @param {Responder} res |
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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
2803
6
1306513
32