Bot Framework v4 multilingual bot sample
This sample shows how to translate incoming and outgoing text using a custom middleware and the Microsoft Translator Text API.
-
[Node.js][4] version 8.5 or higher
# determine node version node --version
-
Microsoft Translator Text API key
To consume the Microsoft Translator Text API, first obtain a key following the instructions in the Microsoft Translator Text API documentation. Paste the key in the
translationKey
setting in the.env
file, or use your preferred configuration and update the following line inindex.js
with your translation key:adapter.use(new TranslatorMiddleware(languagePreferenceProperty, process.env.translatorKey));
- Clone the repository
git clone https://github.com/Microsoft/botbuilder-samples.git
- In a terminal, navigate to
samples/javascript_nodejs/17.multilingual-conversations
cd samples/javascript_nodejs/17.multilingual-conversations
- Install modules
npm install
- Start the bot
npm start
Microsoft Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
- Install the Bot Framework emulator from here
- Launch Bot Framework Emulator
- File -> Open Bot Configuration and navigate to
samples/javascript_nodejs/17.multilingual-conversations
folder - Select
multilingual-conversations.bot
file
Translation Middleware: We create a translation middleware than can translate text from bot to user and from user to bot, allowing the creation of multilingual bots. Users can specify their language preference, which is stored in the user state. The translation middleware translates to and from the user's preferred language.
The Microsoft Translator Text API, Microsoft Translator Text API is a cloud-based machine translation service. With this API you can translate text in near real-time from any app or service through a simple REST API call. The API uses the most modern neural machine translation technology, as well as offering statistical machine translation technology.
You can use the MSBot Bot Builder CLI tool to clone and configure any services this sample depends on.
To install all Bot Builder tools -
Ensure you have Node.js version 8.5 or higher
npm i -g msbot chatdown ludown qnamaker luis-apis botdispatch luisgen
To clone this bot, run
msbot clone services -f deploymentScripts/msbotClone -n <BOT-NAME> -l <Azure-location> --subscriptionId <Azure-subscription-id> --appId <YOUR APP ID> --appSecret <YOUR APP SECRET PASSWORD>
NOTE: You can obtain your appId
and appSecret
at the Microsoft's Application Registration Portal