Using IBM’s Watson with php and Curl

Asked

Viewed 1,070 times

2

Good morning, I’m trying to use the IBM chatbot service Watson. As a test I created my support workflow for a simple pizza order.

At the beginning of the call he welcomes you and asks what pizza I want.

It validates 3 information 1- Quantity 2- flavour 3- goes soda together

in the Watson test on the web panel it runs the Conversation perfectly as programmed. but when I input Curl it keeps repeating the start even though I answer the information the same way I did in the ibm website’s test chatweb input

follow my Cod Curl

    curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic NDkzYzBmZWItMzg2MC00O6RiLTkyMjUtM2E0ODc4MDMxODY3OmGFTFUzdUd1a0NDRg==' -d '{ \ 
   "input": { \ 
     "text": "" \ 
   }   \ 
 }' 'https://watson-api-explorer.mybluemix.net/conversation/api/v1/workspaces/9ec1ac11-786d-4c2d-9d8a-528265e3bcbb/message?version=2017-02-03'

and he gives me back this json

{
  "intents": [],
  "entities": [],
  "input": {
    "text": ""
  },
  "output": {
    "log_messages": [],
    "text": [
      "bem vindo a pizzaria smartphone. quantas pizzas o senhor deseja pedir hoje?"
    ],
    "nodes_visited": [
      "inicio"
    ]
  },
  "context": {
    "conversation_id": "3f4b12da-2c3c-4b04-a94e-2da688ece806",
    "system": {
      "dialog_stack": [
        {
          "dialog_node": "inicio"
        }
      ],
      "dialog_turn_counter": 1,
      "dialog_request_counter": 1,
      "_node_output_map": {
        "inicio": [
          0
        ]
      }
    }
  }
}

how I should forward another request so that it continues in the same conversation and does not show me the start again every time I do Curl.

I tried to send it the following way and it continues with problems:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic NDkzYzBmZWItMzg2MC00O6RiLTkyMjUtM2E0ODc4MDMxODY3OmGFTFUzdUd1a0NDRg==' -d '{ \ 
   "input": { \ 
     "text": "quero uma pizza" \ 
   }, \ 
   "context": { \ 
     "conversation_id": "3f4b12da-2c3c-4b04-a94e-2da688ece806" \ 
    } \ 
 }' 'https://watson-api-explorer.mybluemix.net/conversation/api/v1/workspaces/9ec1ac11-786d-4c2d-9d8a-528265e3bcbb/message?version=2017-02-03'

and he returns to me again the beginning:

{
  "intents": [
    {
      "intent": "qtd-pizza",
      "confidence": 0.9523983001708984
    }
  ],
  "entities": [
    {
      "entity": "qtd-pizza",
      "location": [
        6,
        9
      ],
      "value": "1",
      "confidence": 1
    },
    {
      "entity": "sys-number",
      "location": [
        6,
        9
      ],
      "value": "1",
      "confidence": 1,
      "metadata": {
        "numeric_value": 1
      }
    }
  ],
  "input": {
    "text": "quero uma pizza"
  },
  "output": {
    "log_messages": [],
    "text": [
      "bem vindo a pizzaria smartphone. quantas pizzas o senhor deseja pedir hoje?"
    ],
    "nodes_visited": [
      "inicio"
    ]
  },
  "context": {
    "conversation_id": "3f4b12da-2c3c-4b04-a94e-2da688ece806",
    "system": {
      "dialog_stack": [
        {
          "dialog_node": "inicio"
        }
      ],
      "dialog_turn_counter": 1,
      "dialog_request_counter": 1,
      "_node_output_map": {
        "inicio": [
          0
        ]
      }
    }
  }
}

I would like some guidance on how to proceed. Reading the json, Curl and etc I’m doing through a php and just need help with the working logic of Watson. Thanks in advance for your attention.

follows Watson api link and explorer api for online testing

https://www.ibm.com/watson/developercloud/conversation/api/v1/#send_message

https://watson-api-explorer.mybluemix.net/apis/conversation-v1#! /message/message

  • Please put the link to the Watson API.

  • added in the main post

1 answer

4


Hello. I’m not sure so far, but I believe the problem lies in the "context" of your request.

You must save the entire received context in the first answer (including conversation_id, system, dialog_turn_counter, dialog_request_counter and context vars if you have it) and then send it when making a new request.

In your example you are sending "context" only with conversation_id.

You can see examples of this in the documentation, here:

https://www.ibm.com/watson/developercloud/doc/conversation/develop-app.html#maintaining-state

// Prompt for the next round of input.
var newMessageFromUser = prompt('>> ');
// Send back the context to maintain state.
conversation.message({
  input: { text: newMessageFromUser },
  context : response.context, <--- O context é devolvido da mesma forma que o Watson envia.
}, processResponse)

and here:https://www.ibm.com/watson/developercloud/conversation/api/v1/? Curl#send_message

Browser other questions tagged

You are not signed in. Login or sign up in order to post.