This is a Cloud Function designed to be used with Watson Assistant and Language Translator in order to translate a conversation with a user from English to their preferred language without the need for an orchestration layer.
- You should have an instance of Watson Assistant, Language Translator, and Cloud Functions created in your IBM Cloud account
- Install the IBM Cloud CLI
- Install Node.js
-
If you haven't already, create an instance each of Watson Assistant, Language Translator, and Cloud Functions
-
Download the files in this repository:
git clone https://github.com/modlanglais/wa-translator
-
Import
skill-WA-Translator.json
to your Watson Assistant instance -
Create and attach an Assistant to your skill and make note of the API key, assistant ID, and URL
-
Run
npm install
in the project directory to install the dependencies -
Open
index.js
and update the following with your service credentials:let wa_apikey = "{your-watson-assisatant-api-key}"; let wa_url = "{watson-assistant-url}"; let wa_version = "{watson-assistant-version}"; let assistantId = "{assistant-id-to-translate}"; let lt_apikey = "{your-language-translator-api-key}"; let lt_url = "{language-translator-url}"; let lt_version = "{language-translator-version}";
This will add your credentials for your specific Watson Assistant (wa_) and Language Translator (lt_) services.
-
Open your Terminal and navigate to the root directory of your app. Then zip all of your application files together using the following command:
zip -r my-action.zip *
You can replace
my-action.zip
with the name of your choosing, i.e.wa-translator.zip
ormorgans-function.zip
-
In the terminal, login to your IBM Cloud account using the CLI:
ibmcloud login
If you have trouble, please see the documentation. You will need to use the IBM Cloud CLI to point to the namespace in which you created your Cloud Function
-
Issue the following command to push your new zipped Cloud Function to your IBM Cloud Functions service:
ibmcloud fn action create my-action my-action.zip --kind nodejs:10
You can replace
my-action
with whatever you would like to name your cloud function.my-action.zip
should reflect the name of the .zip file you created in step 5 -
(Optional) If you make changes to
index.js
and need to push the new changes, use the following command to update your functionibmcloud fn action update my-action my-action.zip --kind nodejs:10
-
Open your Cloud Functions dashboard here: https://cloud.ibm.com/functions/
-
Select the namespace you wish to deploy the function in from the drop-down, then click "Actions" on the left nav bar
-
Click my-action or the name that you previously gave your action in step 7
-
Select Endpoints then check "Enable as web action" and click "Save"
-
Copy the URL in the "Web Action" section and save for later
-
Open the skill you imported in Watson Assistant earlier
-
Replace this URL with your webhook URL that you copied in step 15
-
Important: Make sure you append ".json" to the end of this URL in order for Watson Assistant to process the data correctly
-
That's it! Your user may now select their preferred language and Language Translator will automatically translate your English-language chatbot.
To debug and run locally... un-comment the last line in index.js
which invokes the main() method. Then run as you would any Node app: node index.js