Using IBM Watson with php and Curl

2

Good morning, I'm trying to use the IBM chatbot service on watson. As a test I created my workflow for a simple pizza order.

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

It validates 3 information 1- Quantity 2- flavor 3- If it goes refrigerant together

In the watson test in the web panel it works the conversation perfectly as I programmed it. but when I give the entry in the curl it keeps repeating the start even if I answer the information the same way I did in the input to chatweb test of the ibm site

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 it returns me 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 should I resend another request so that it continues in the same conversation and does not show me the start again every time I do the curl.

I tried to send it as follows and it still has 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 it returns me the beginning again:

{
  "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 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. Thank you in advance for your attention.

follow watson's api link and api explorer for online testing

link

link

    
asked by anonymous 06.04.2017 / 15:47

1 answer

4

Hello. I'm not sure yet, but I believe the problem is in the context of your request.

You should save all the context you received in the first response (including conversation_id, system, dialog_turn_counter, dialog_request_counter and context vars if you have one) and then send it when you make a new request.

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

You can see examples of this in the documentation here:

link

// 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: link

    
08.04.2017 / 01:20