Our website supports German and English languages. So I added German and English widget languages and I created a German bot and an English bot.
The widget language is selected based on the browser visitor language.
But how can I select the language of the ChatBot?
Yes you can create different ChatBots for different languages.
The easy way to do it is:
- Create two Chatbots. One for Italian and another for English:
- Create a department for each language and attach the relative chatbot based on language to each department like below:
- For each department insert in the department description his language as below:
Note The language in the description and the Chatbot language must match.
- Filter the department based on your browser language
On your website modify your script using the onBeforeDepartmentsFormRender event as in the following example:
<script type="application/javascript">
window.Tiledesk('onBeforeDepartmentsFormRender', function(event_data) {
var departments = event_data.detail.departments;
var lang = window.tiledesk.angularcomponent.component.g.lang;
if (lang && lang === 'en') {
var new_deps = departments.filter(function(dep) {
if (dep.description && dep.description.includes('English')) {
return dep;
}
});
} else {
var new_deps = departments.filter(function(dep) {
if (dep.description && dep.description.includes('Italian')){
return dep;
}
});
}
//modify the department array by reference
departments.length=0; //empty the array
console.log("new_deps",new_deps);
new_deps.forEach(function(d) { //populate the department array
departments.push(d);
});
});
</script>
More info about onBeforeDepartmentsFormRender event here: Web SDK - Tiledesk Docs
Let me know
Andrea
You can also use triggers to switch to different bot languages
These are the steps:
- Create two Chatbots. One for Italian and another for English:
- Go to System trigger and edit the Invite Bot
- Edit the Invite Bot trigger adding
- The language condition (ex. English)
- Change the action to Launch bot selecting the chatbot for the specific language
- Create another Invite Bot trigger for the Italian language as follow: