Giter VIP home page Giter VIP logo

how-to-integrate-watson-assistant-with-ibm-cloud-function's Introduction

How to integrate Watson Assistant with IBM Cloud Function

Hello everyone, today we are going to integrate Watson Assistant by using IBM Cloud functions This is very interesting way to give power to you Chatbot with a fully serveless system in IBM Cloud.

Step 1 - Login to your IBM Cloud.

First you need to login to your IBM Cloud here https://cloud.ibm.com

Step 2 - Create an Cloud Function

Type functions in the search bar type function

Then you select Start Creating then you create Namespace, then you select Actions

and click Create then you have created your serverless For this example, instead use node.js we use Python

we copy the following code and replace the current one

import sys
import requests
import json
def main(params):
    # Used to identify the specific task being called from Watson Assistant
    # URL used for API call
    print(params)
    url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + str(params['object_of_interest'])+ "?redirect=true"
    # Set headers
    headers = {'accept': 'application/json'}
    # Make API call
    r = requests.get(url,headers)
    # Process failed API call
    if r.status_code != 200:
        return {
            'statusCode': r.status_code,
            'headers': { 'Content-Type': 'application/json'},
            'body': {'message': 'Error processing your request'}
        }
    # Process successful API call 
    else:
        res = json.loads(r.content)
        extract = res['extract']
        return {
            'statusCode': 200,
            'headers': { 'Content-Type': 'application/json'},
            'extract': {"extract":extract}
        }

to test we can click on Invoke with parameters

{
    "object_of_interest":"gravity"
  }

and then we click Invoke

we got the following

Step 4 - Enable Endpoint

Before create API we go to Endpoints and we click on Enable as Web Action and click save and then we copy the HTTP method

now it works our cloud function.

Step 5 - Call Cloud Function from Watson Assistant

In the menu of Watson Assistant we select the tab Assistant Settings we scroll down and we click Activate dialog At the Home menu we click Dialog

#Step 5 - Create Entity We create am entitiy @object_of_interest

#Step 6 - Create Intent Then we create an intent, , for example we type for the Intent name #tell_me_about and in the user example we add different queries that countains the nouns that you will look on, or will be used as arguments. eg. what is the definition of gravity then you e click on Annotate entities and click with the mouse gravity and click the @object_of_interest you will got something like

Step 6 - Weebhook setup

We paste our edpoint copied here, and we add the extension .json at the end of the URL. Here we do not need add, extra Header, or autorization.

Step 7- Create Dialog

We go the menu Dialog and we Create dialog

We click on Add node and in the section If assistant recognizes, we add the condition #tell_me_about and @object_of_interest

Then in the part of Parameters we add the following parameters

then we click on Customize

and we enable Call out to webhook/actions and select Call a webhook click apply in the part of Assistat responds you will have

If assistant recognizes:

$webhook_result_1

the you click the gear button of Respond with and you add the following in the Text responds

I am defining @object_of_interest:<? $webhook_result_1.extract.extract ?>

and click save

then you will get something like

with Now finally we can try it and you can ask questions

how-to-integrate-watson-assistant-with-ibm-cloud-function's People

Contributors

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