Coder Social home page Coder Social logo

modcarroll / wa-translator Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 4.51 MB

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.

License: Apache License 2.0

JavaScript 100.00%
translate watson chatbot cloudfunction openwhisk

wa-translator's Introduction

Watson Assistant Translations from Cloud Functions

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.

Demo

translator-bot

Prerequisites

  • 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

Part I: Import the skill to your Watson Assistant Instance

  1. If you haven't already, create an instance each of Watson Assistant, Language Translator, and Cloud Functions

  2. Download the files in this repository: git clone https://github.com/modlanglais/wa-translator

  3. Import skill-WA-Translator.json to your Watson Assistant instance

  4. Create and attach an Assistant to your skill and make note of the API key, assistant ID, and URL

Part II: Create the Cloud Function

  1. Run npm install in the project directory to install the dependencies

  2. 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.

  3. 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 or morgans-function.zip

  4. 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

  5. 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

  6. (Optional) If you make changes to index.js and need to push the new changes, use the following command to update your function

    ibmcloud fn action update my-action my-action.zip --kind nodejs:10

Part III: Retrieve your IBM Cloud Function URL

  1. Open your Cloud Functions dashboard here: https://cloud.ibm.com/functions/

  2. Select the namespace you wish to deploy the function in from the drop-down, then click "Actions" on the left nav bar

    cf-screenshot

  3. Click my-action or the name that you previously gave your action in step 7

  4. Select Endpoints then check "Enable as web action" and click "Save"

  5. Copy the URL in the "Web Action" section and save for later

    cf-webaction

Part IV: Add the Webhook to Your Chatbot

  1. Open the skill you imported in Watson Assistant earlier

  2. Navigate to Options -> Webhooks wa-webhooks

  3. Replace this URL with your webhook URL that you copied in step 15

  4. Important: Make sure you append ".json" to the end of this URL in order for Watson Assistant to process the data correctly

  5. That's it! Your user may now select their preferred language and Language Translator will automatically translate your English-language chatbot.

Debugging

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

wa-translator's People

Contributors

dependabot[bot] avatar modcarroll avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.