JB
<pre>
Here is my method, I have added this , action = {...action,...parsedData}; but still data is not getting merged data.actions can you see where is the issue</pre>
<pre>
async processJsonData3(jsonData: any[]): Promise<any> {
const resultMap = {};
// Since jsonData is now inside the request object and is an array, we'll iterate over it
for (const data of jsonData) {
const index: number = jsonData.indexOf(data);
let intent = 'Unknown'; // Default value for intent
if (data.queryResult && data.queryResult.intent) {
intent = data.queryResult.intent.displayName;
}
const userInput = data.queryResult.text;
const messagesDisplayed: string[] = [];
const optionsDisplayed: string[] = [];
const userActions = data.actions || [];
data.queryResult.responseMessages.forEach((message: any) => {
if (message.text && message.text.text) {
messagesDisplayed.push(...message.text.text);
}
if (message.payload && message.payload.richContent) {
message.payload.richContent.forEach((content: any) => {
content.forEach((item: any) => {
if (item.type === 'chips') {
const chipOptions = item.options.map((option: any) => option.text);
optionsDisplayed.push(...chipOptions);
}
});
});
}
});
for (let action of data.actions) {
const text = action.encData;
if (action.encData) {
try {
let decryptedData = await this.cryptoUtil.decrypt(action.encData, '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF');
if (typeof decryptedData === 'string') {
const parsedData = JSON.parse(decryptedData);
if (typeof parsedData === 'object') {
action = {...action,...parsedData};
} else {
new Logger().log('Decrypted Data is not an object.');
}
} else {
new Logger().log('Decrypted Data is not a string.');
}
} catch (error) {
console.error('Decryption error:', error);
}
}
}
// Grouping actions by IntentName
const actionsByIntent = data.actions.reduce((acc: any, action: any) => {
const intentName = action.IntentName;
if (!acc[intentName]) acc[intentName] = [];
acc[intentName].push(action);
return acc;
}, {});
const key = `${intent}`; // Form the key as "index-IntentName"
resultMap[key] = {
intent,
userInput,
messagesDisplayed,
optionsDisplayed,
userActions: actionsByIntent,
};
}
return resultMap;
}</pre>