The Windhover
The Windhover

Reputation: 342

Can I create an IBM Watson Conversation client application in Javascript without using Node.js?

Can I create an IBM Watson Conversation client application in Javascript without using Node.js? The ERP software that I'm working in does not allow usage of Node.js. What would a POST request to Watson look like in plain javascript? I see that I need some user/pass credentials, the POST URL. But how do I send the Watson service data? What does the data object need to look like? All the API documentation is using Node.

Upvotes: 1

Views: 234

Answers (3)

bigburger554
bigburger554

Reputation: 78

As long as you have some way of running javascript on the server you can make a request to IBM Watson with javascript since POST requests to Watson have to be run server side using a proxy.

Upvotes: 2

Mitch
Mitch

Reputation: 839

There is a java sdk for this. As well as Java listed in the API reference. API ref: https://www.ibm.com/watson/developercloud/assistant/api/v1/java.html?java SDK: https://github.com/watson-developer-cloud/java-sdk/tree/master/assistant

Upvotes: 1

mpjjonker
mpjjonker

Reputation: 947

I believe you can if you follow the CURL documentation here: https://www.ibm.com/watson/developercloud/assistant/api/v1/curl.html?curl#message

curl -X POST -u "{username}":"{password}" --header "Content-Type:application/json" -- 
data "{\"input\": {\"text\": \"Hello\"}}" 
"https://gateway.watsonplatform.net/assistant/api/v1/workspaces/9978a49e-ea89-4493- 
b33d-82298d3db20d/message?version=2018-07-10"

In the following request make sure you provide the context JSON that is returned in the response to the previous request This is an example of the (first) response

{
  "intents" : [ {
    "intent" : "hello",
    "confidence" : 0.9755029201507568
  } ],
  "entities" : [ ],
  "input" : {
    "text" : "Hello"
  },
  "output" : {
    "generic" : [ {
      "response_type" : "text",
      "text" : "Hello! What can I do for you?"
    } ],
    "text" : [ "Hello! What can I do for you?" ],
    "nodes_visited" : [ "greeting" ],
    "log_messages" : [ ]
  },
  "context" : {
    "conversation_id" : "a96ec62f-773c-4e84-8be9-f9dbca9f83d0",
    "system" : {
      "dialog_stack" : [ {
        "dialog_node" : "root"
      } ],
      "dialog_turn_counter" : 1,
      "dialog_request_counter" : 1,
      "_node_output_map" : {
        "greeting" : {
          "0" : [ 0, 0 ]
        }
      },
      "branch_exited" : true,
      "branch_exited_reason" : "completed"
    }
  }
}

Upvotes: 0

Related Questions