-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateCxoneScript.js
More file actions
36 lines (27 loc) · 1.04 KB
/
generateCxoneScript.js
File metadata and controls
36 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const fs = require("fs");
const path = require("path");
function convertHtmlToCxoneScript(html) {
let script = 'ASSIGN formCode=""\n';
const lines = html.split(/\r?\n/);
lines.forEach(line => {
const trimmed = line.trim();
if (trimmed.length === 0) return;
// replace normal quotes with {char(34)}
const converted = trimmed.replace(/"/g, "{char(34)}");
script += `formCode.append("${converted}")\n`;
});
return script;
}
function generateScriptFromFile(htmlFilePath, outputFilePath = "cxoneScript.txt") {
try {
const html = fs.readFileSync(path.resolve(htmlFilePath), "utf8");
console.log("HTML file loaded successfully... converting...");
const result = convertHtmlToCxoneScript(html);
fs.writeFileSync(outputFilePath, result);
console.log(`CXone script file generated: ${outputFilePath}`);
} catch (error) {
console.error("Error processing file:", error.message);
}
}
// Call function: First argument = HTML file, second = output file name
generateScriptFromFile("form.html", "cxoneOutput.txt");