moving console.js to correct package structure
This commit is contained in:
parent
94b441f769
commit
d2e9bcfa85
@ -0,0 +1,64 @@
|
|||||||
|
const { recognizedObject: r = {} } = this;
|
||||||
|
|
||||||
|
class WebdisConsole {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
log(...data) {
|
||||||
|
this.info(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(...data) {
|
||||||
|
this.#log("DEBUG", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
info(...data) {
|
||||||
|
this.#log("INFO", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
warn(...data) {
|
||||||
|
this.#log("WARN", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
error(...data) {
|
||||||
|
this.#log("ERROR", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
input(...data) {
|
||||||
|
this.#log("INPUT", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
answer(...data) {
|
||||||
|
this.#log("ANSWER", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#publishToWebdis(channel, message) {
|
||||||
|
const webdisBaseURL = "https://iva.mortons.site/webdis/";
|
||||||
|
|
||||||
|
const str = JSON.stringify(message);
|
||||||
|
const encodedStr = buffer.Buffer.from(str).toString("base64");
|
||||||
|
let escapedStr = encodedStr.replace(/\//g, "%2f");
|
||||||
|
escapedStr = escapedStr.replace(/\+/g, "%2B");
|
||||||
|
|
||||||
|
axios.post(webdisBaseURL, `PUBLISH/${channel}/${escapedStr}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
#log(level, ...data) {
|
||||||
|
try {
|
||||||
|
this.#publishToWebdis(r.workspaceId + ".console", {
|
||||||
|
conversationId: r.conversationId,
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
level: level,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
r.errorInfo = {
|
||||||
|
...r.errorInfo,
|
||||||
|
label: {
|
||||||
|
data: error.toJSON ? error.toJSON() : {},
|
||||||
|
message: error.message,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WebdisConsole();
|
||||||
@ -1,45 +0,0 @@
|
|||||||
const { recognizedObject: r = {} } = this;
|
|
||||||
|
|
||||||
class WebdisConsole {
|
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
log(...data) {
|
|
||||||
this.info(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug(...data) {
|
|
||||||
this.#log("DEBUG", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
info(...data) {
|
|
||||||
this.#log("INFO", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
warn(...data) {
|
|
||||||
this.#log("WARN", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
error(...data) {
|
|
||||||
this.#log("ERROR", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#log(level, ...data) {
|
|
||||||
webdis()
|
|
||||||
.publish(r.workspaceId + ".console", {
|
|
||||||
conversationId: r.conversationId,
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
level: level,
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
r.errorInfo = {
|
|
||||||
...r.errorInfo,
|
|
||||||
label: {
|
|
||||||
data: error.toJSON ? error.toJSON() : {},
|
|
||||||
message: error.message,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WebdisConsole();
|
|
||||||
Loading…
x
Reference in New Issue
Block a user