Obtaining relevant fields from Watson Discovery search results as Watson assistant response

227 Views Asked by At

I am using watson assistant webhooks to call a watson discovery query action. Using $webhook_result_1.passages, I'm getting all the passage fields. I want the assistant response as the passage_text field only. I have tried everything like $webhook_result_1.passages.passage_text, $webhook_result_1.passages[0].passage_text but nothing seems to work.

{
"matching_results": 14,
"session_token": "1_xvrscQ9w1x7chIp2_HWOk4wS8K",
"passages": [
    {
        "document_id": "3a5efee70d8cc9d70e2b94d22c15e2d1_8",
        "passage_score": 8.335406752877208,
        "passage_text": "If you have a furnace or boiler installed: 1. Select the heating menu. 2. Configure the heater type:  Furnace: Optimizes ecobee3 for systems using forced air  Boiler: Optimizes your ecobee3 for systems using radiators or in-floor heat. 3.",
        "start_offset": 0,
        "end_offset": 240,
        "field": "text"
    },
1

There are 1 best solutions below

1
DSeager On

See Expression language methods

For a context variable named testarray with value [{"text":"value"},{"text":"2"}] in the dialog response text I can use this to output the 'text' property from the first object:

 <? context.testarray.get(0).get("text").getAsString() ?>

You may therefore need:

Passage is : <?context.webhook_result_1.passages.get(0).get("passage_text").getAsString() ?>