Commit 6a0faa83 by Pavel Fedorov

поменял индекс на dev

1 parent c95e54b5
Showing with 5 additions and 73 deletions
...@@ -11,14 +11,6 @@ const preset_template_id = 1; ...@@ -11,14 +11,6 @@ const preset_template_id = 1;
const logs_path = "./logs/"; const logs_path = "./logs/";
const file_mime_type = "text/plain"; const file_mime_type = "text/plain";
let txtData = "";
let abonent_phone = process.argv[2] ?? "";
let caller_phone = process.argv[3] ?? abonent_phone;
const report_file = "jobs/" + caller_phone + ".json";
const pid_file = report_file.replace( /\.json$/, '.pid' );
fs.writeFileSync(pid_file, JSON.stringify(process.pid, undefined, 2));
fs.chmod(pid_file, 0o666, (err) => { if (err) console.log(err) });
function nextInterval(iterationNum) { function nextInterval(iterationNum) {
var x = iterationNum; var x = iterationNum;
// Максимальный период ожидания 10 минут // Максимальный период ожидания 10 минут
...@@ -58,32 +50,6 @@ async function main() { ...@@ -58,32 +50,6 @@ async function main() {
return dasha.audio.fromFile(fname); return dasha.audio.fromFile(fname);
}; };
process.on("SIGTERM", async () => {
console.log("\nReceived SIGTERM");
await app.stop();
app.dispose();
if (fs.existsSync(pid_file)) await fs.unlinkSync(pid_file);
let job_data = { status: "Terminated",
reason: "Received SIGTERM",
details: txtData };
fs.writeFileSync(report_file, JSON.stringify(job_data, undefined, 2),
{encoding:'utf8', mode:0o666, flag:'w'});
console.log(job_data);
});
process.on("SIGINT", async () => {
console.log("\nReceived SIGINT");
await app.stop();
app.dispose();
if (fs.existsSync(pid_file)) await fs.unlinkSync(pid_file);
let job_data = { status: "Terminated",
reason: "Received SIGINT",
details: txtData };
fs.writeFileSync(report_file, JSON.stringify(job_data, undefined, 2),
{encoding:'utf8', mode:0o666, flag:'w'});
console.log(job_data);
});
app.setExternal("numbers_from_text", async (args) => { app.setExternal("numbers_from_text", async (args) => {
return await shared.cct_numbers_from_text(args.text); return await shared.cct_numbers_from_text(args.text);
}); });
...@@ -166,8 +132,10 @@ async function main() { ...@@ -166,8 +132,10 @@ async function main() {
await app.start(); await app.start();
const input_context = { phone: abonent_phone, caller: caller_phone }; let abonent_phone = process.argv[2] ?? "";
const conv = app.createConversation(input_context); let caller_phone = process.argv[3] ?? abonent_phone;
const conv = app.createConversation({ phone: abonent_phone,
caller: caller_phone });
const audioChannel = conv.input.phone !== "chat"; const audioChannel = conv.input.phone !== "chat";
if (audioChannel) { if (audioChannel) {
...@@ -214,7 +182,6 @@ async function main() { ...@@ -214,7 +182,6 @@ async function main() {
let check_prefix = toUser.substring(0, 4); let check_prefix = toUser.substring(0, 4);
if (local_num == check_prefix) toUser = toUser.substring(4); if (local_num == check_prefix) toUser = toUser.substring(4);
// Make log & debug files names // Make log & debug files names
let txt_file_name = logs_path + 'out-' + toUser + '-' let txt_file_name = logs_path + 'out-' + toUser + '-'
+ local_num + '-' + solid_date + '-' + local_num + '-' + solid_date + '-'
...@@ -232,7 +199,7 @@ async function main() { ...@@ -232,7 +199,7 @@ async function main() {
const debugFile = await fs.promises.open(debug_file_name, "w"); const debugFile = await fs.promises.open(debug_file_name, "w");
caller_phone = shared.human_format(conv.input.caller); caller_phone = shared.human_format(conv.input.caller);
txtData = "\t" + caller_phone + "\t-=#=-\t" + time_mark + "\n\n"; let txtData = "\t" + caller_phone + "\t-=#=-\t" + time_mark + "\n\n";
await txtFile.appendFile(txtData); await txtFile.appendFile(txtData);
debugString = 'Initialize call to: ' + toUser + "\n"; debugString = 'Initialize call to: ' + toUser + "\n";
...@@ -274,18 +241,7 @@ async function main() { ...@@ -274,18 +241,7 @@ async function main() {
await debugFile.appendFile(debugString); await debugFile.appendFile(debugString);
}); });
let connectionStatus = {};
if (audioChannel)
connectionStatus = { status: "Connected", reason: "", details: "" };
else
connectionStatus = { status: "Chat mode", reason: "", details: "" };
conv.on("debugLog", async (event) => { conv.on("debugLog", async (event) => {
if (event?.msg?.msgId === "FailedOpenSessionChannelMessage") {
connectionStatus = { status: "Failed",
reason: event?.msg?.reason,
details: event?.msg?.details };
}
if (event?.msg?.msgId === "RecognizedSpeechMessage") { if (event?.msg?.msgId === "RecognizedSpeechMessage") {
const logEntry = event?.msg?.results[0]?.facts; const logEntry = event?.msg?.results[0]?.facts;
await logFile.appendFile(JSON.stringify(logEntry, undefined, 2) + "\n"); await logFile.appendFile(JSON.stringify(logEntry, undefined, 2) + "\n");
...@@ -329,13 +285,6 @@ async function main() { ...@@ -329,13 +285,6 @@ async function main() {
conversation_status_id = "unknown"; conversation_status_id = "unknown";
conversation_status = "Не определённое в сценанрии завершение разговора"; conversation_status = "Не определённое в сценанрии завершение разговора";
} }
if (connectionStatus.status === "Failed") {
if (connectionStatus.reason === "Busy") {
conversation_status = "линия занята";
} else {
conversation_status = "абонент не взял трубку";
}
}
speaker = " sys"; speaker = " sys";
replic = speaker + ': [' + hours + ':' + minutes + ':' + seconds + ' ' replic = speaker + ': [' + hours + ':' + minutes + ':' + seconds + ' '
+ dts_m + ':' + dts_s + "] - / " + conversation_status + " /\n"; + dts_m + ':' + dts_s + "] - / " + conversation_status + " /\n";
...@@ -360,21 +309,6 @@ async function main() { ...@@ -360,21 +309,6 @@ async function main() {
await txtFile.appendFile(audio_url); await txtFile.appendFile(audio_url);
await logFile.appendFile(audio_url); await logFile.appendFile(audio_url);
let job_data = {};
if (connectionStatus.status === "Failed")
job_data = connectionStatus;
else {
job_data = { status: connectionStatus.status,
reason: conversation_status_id,
audio: result.recordingUrl,
report: result.output,
details: txtData };
}
fs.writeFileSync(report_file, JSON.stringify(job_data, undefined, 2),
{encoding:'utf8', mode:0o666, flag:'w'});
console.log(job_data);
const conv_info = shared.get_conversation_info(app, conv); const conv_info = shared.get_conversation_info(app, conv);
// Close text, log and debug files // Close text, log and debug files
...@@ -450,8 +384,6 @@ async function main() { ...@@ -450,8 +384,6 @@ async function main() {
await app.stop(); await app.stop();
app.dispose(); app.dispose();
if (fs.existsSync(pid_file)) await fs.unlinkSync(pid_file);
} }
main().catch((err) => {console.error(err)}); main().catch((err) => {console.error(err)});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!