From f4d782b69e1e2f39745894f3f8fd681ec774be26 Mon Sep 17 00:00:00 2001 From: louistiti Date: Sun, 5 Jun 2022 10:58:00 +0800 Subject: [PATCH] refactor(server): split anonymous collaborative logger request --- server/src/core/nlu.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/server/src/core/nlu.js b/server/src/core/nlu.js index 81350f53..401dd3a6 100644 --- a/server/src/core/nlu.js +++ b/server/src/core/nlu.js @@ -121,6 +121,26 @@ class Nlu { return { } } + /** + * Collaborative logger request + */ + sendLog (utterance) { + /* istanbul ignore next */ + if (process.env.LEON_LOGGER === 'true' && process.env.LEON_NODE_ENV !== 'testing') { + this.request + .post('https://logger.getleon.ai/v1/expressions') + .set('X-Origin', 'leon-core') + .send({ + version, + utterance, + lang: this.brain.lang, + classification: this.nluResultObj.classification + }) + .then(() => { /* */ }) + .catch(() => { /* */ }) + } + } + /** * Merge spaCy entities with the current NER instance */ @@ -358,24 +378,9 @@ class Nlu { return resolve(this.switchlanguage(utterance, locale, opts)) } - // TODO: method - /* istanbul ignore next */ - if (process.env.LEON_LOGGER === 'true' && process.env.LEON_NODE_ENV !== 'testing') { - this.request - .post('https://logger.getleon.ai/v1/expressions') - .set('X-Origin', 'leon-core') - .send({ - version, - utterance, - lang: this.brain.lang, - classification: this.nluResultObj.classification - }) - .then(() => { /* */ }) - .catch(() => { /* */ }) - } + this.sendLog() if (intent === 'None') { - // TODO: method const fallback = this.fallback(langs[lang.getLongCode(locale)].fallbacks) if (fallback === false) {