@peopl-health/nexus 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,10 +34,10 @@ const addInsAssistantController = async (req, res) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const addMsgAssistantController = async (req, res) => {
|
|
37
|
-
const { code, messages, reply = false } = req.body;
|
|
37
|
+
const { code, messages, role = 'user', reply = false } = req.body;
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
|
-
const ans = await addMsgAssistant(code, messages, reply);
|
|
40
|
+
const ans = await addMsgAssistant(code, messages, role, reply);
|
|
41
41
|
if (ans) await sendMessage({code, body: ans, fileType: 'text'});
|
|
42
42
|
return res.status(200).send({ message: 'Add message to the assistant' });
|
|
43
43
|
} catch (error) {
|
|
@@ -18,6 +18,55 @@ const checkTemplateSupport = () => {
|
|
|
18
18
|
};
|
|
19
19
|
const { handleApiError } = require('../utils/errorHandler');
|
|
20
20
|
|
|
21
|
+
// Checks if a label is valid (non-null, non-undefined, non-empty string)
|
|
22
|
+
const isValidLabel = (label) => {
|
|
23
|
+
return label !== null &&
|
|
24
|
+
label !== undefined &&
|
|
25
|
+
typeof label === 'string' &&
|
|
26
|
+
label.trim() !== '';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Generates a label for a layout item based on available fields
|
|
30
|
+
const generateLabel = (item, index) => {
|
|
31
|
+
if (item.name && typeof item.name === 'string' && item.name.trim() !== '') {
|
|
32
|
+
return item.name.trim();
|
|
33
|
+
}
|
|
34
|
+
if (item.type && typeof item.type === 'string') {
|
|
35
|
+
return `${item.type}_${index + 1}`;
|
|
36
|
+
}
|
|
37
|
+
return `element_${index + 1}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Ensures all layout elements have a valid label
|
|
41
|
+
const ensureLabels = (pages) => {
|
|
42
|
+
if (!Array.isArray(pages)) {
|
|
43
|
+
return pages;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return pages.map((page) => {
|
|
47
|
+
if (!page || typeof page !== 'object' || !page.layout || !Array.isArray(page.layout)) {
|
|
48
|
+
return page;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const processedLayout = page.layout.map((item, index) => {
|
|
52
|
+
if (!item || typeof item !== 'object') {
|
|
53
|
+
return item;
|
|
54
|
+
}
|
|
55
|
+
if (isValidLabel(item.label)) {
|
|
56
|
+
return { ...item, label: item.label.trim() };
|
|
57
|
+
}
|
|
58
|
+
const newLabel = generateLabel(item, index);
|
|
59
|
+
|
|
60
|
+
if (!isValidLabel(newLabel)) {
|
|
61
|
+
return { ...item, label: `element_${index + 1}` };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { ...item, label: newLabel };
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return { ...page, layout: processedLayout };
|
|
68
|
+
});
|
|
69
|
+
};
|
|
21
70
|
|
|
22
71
|
const createFlow = async (req, res) => {
|
|
23
72
|
try {
|
|
@@ -35,6 +84,9 @@ const createFlow = async (req, res) => {
|
|
|
35
84
|
});
|
|
36
85
|
}
|
|
37
86
|
|
|
87
|
+
// Ensure all layout elements have labels (Twilio requirement)
|
|
88
|
+
const processedPages = ensureLabels(pages);
|
|
89
|
+
|
|
38
90
|
// Generate unique identifiers for anti-rejection
|
|
39
91
|
const timestamp = Date.now().toString();
|
|
40
92
|
const uniqueId = require('uuid').v4().substring(0, 6);
|
|
@@ -51,7 +103,7 @@ const createFlow = async (req, res) => {
|
|
|
51
103
|
body: body,
|
|
52
104
|
button_text: buttonText,
|
|
53
105
|
subtitle: subtitle || null,
|
|
54
|
-
pages:
|
|
106
|
+
pages: processedPages,
|
|
55
107
|
type: flowType
|
|
56
108
|
}
|
|
57
109
|
}
|