$caila.detectLanguage
Identifies the text language using the fastText NLP model.
Syntax
The method accepts an array of strings as the only argument. The method returns an array of ISO language codes that the corresponding texts are written in.
- ECMAScript 5
- ECMAScript 6
$caila.detectLanguage([
"This is an English sentence.",
"Yy kaa koo",
"Les hommes naissent et demeurent libres et égaux en droits."
]); // => ["en", "fi", "fr"]
In the ECMAScript 6 runtime, the method is asynchronous:
await $caila.detectLanguage([
"This is an English sentence.",
"Yy kaa koo",
"Les hommes naissent et demeurent libres et égaux en droits."
]); // => ["en", "fi", "fr"]
caution
The method may return unpredictable results when dealing with strings consisting only of numbers, punctuation, or other special characters, as well as texts in multiple languages at once.
How to use
The following example illustrates how to use the method for routing unrecognized requests.
- ECMAScript 5
- ECMAScript 6
state: CatchAll
event!: noMatch
script:
$temp.language = $caila.detectLanguage([$parseTree.text])[0]; // Identify the language.
$session.catchAllCounter = $session.catchAllCounter + 1 || 1; // Increment the counter of unrecognized requests.
# If the client does not speak English, transfer to the agent immediately.
# If they do, transfer to the agent as soon as the counter exceeds the threshold.
if: $temp.language !== "en" || $session.catchAllCounter > 3
go!: /Switch
random:
a: I’m sorry, I didn’t catch that. Could you repeat, please?
a: I didn’t quite get it. Would you mind repeating that for me?
a: Could you say that again? I can’t hear you very well.
state: CatchAll
event!: noMatch
scriptEs6:
$temp.language = (await $caila.detectLanguage([$parseTree.text]))[0]; // Identify the language.
$session.catchAllCounter = $session.catchAllCounter + 1 || 1; // Increment the counter of unrecognized requests.
# If the client does not speak English, transfer to the agent immediately.
# If they do, transfer to the agent as soon as the counter exceeds the threshold.
if: $temp.language !== "en" || $session.catchAllCounter > 3
go!: /Switch
random:
a: I’m sorry, I didn’t catch that. Could you repeat, please?
a: I didn’t quite get it. Would you mind repeating that for me?
a: Could you say that again? I can’t hear you very well.