billoverton
billoverton

Reputation: 2875

How do I return an answer from QnA Maker connector to Power Virtual Agent?

I am playing around with the Power Virtual Agent composer, but I can't get my connector to QnA Maker to work. The URL works via SoapUI, but I get the below object from the "Answers". Any attempt to Parse JSON, Initialize a variable, or otherwise try to get the "answer" text causes the incoming request to fail. I can't find any examples of setting this up in their documentation. Can anyone help me figure out how I can return the QnA Maker answer to the Power Virtual Agent?

{"output": [{
   "answer": "I'm the EBS Bot! Nice to meet you!",
   "score": 100,
   "id": 55,
   "source": "qna_chitchat_professional.tsv",
   "metadata": [   {
      "name": "editorial",
      "value": "chitchat"
   }],
   "context":    {
      "isContextOnly": false,
      "prompts": []
   }
}]}

And here's what the flow looks like

QnA Maker Flow

Upvotes: 0

Views: 471

Answers (2)

billoverton
billoverton

Reputation: 2875

Hury Shen pointed me in the right direction but it didn't quite work to get the QnA Answer. Initializing a variable like in his suggestion triggers an "Apply to each" block since "Answers" is an array. Actually no variable is needed at all, you can just parse the response directly via

body('Generate_answer')['answers'][0]['answer'].

I return this as JSON in the Response Body (I called it output but it could be anything) to be consumed by the Virtual Agent. Here is a screenshot showing the flow:

enter image description here

Upvotes: 2

Hury Shen
Hury Shen

Reputation: 15724

As you mentioned in your question, you get the below object from the "Answers":

{"output": [{
   "answer": "I'm the EBS Bot! Nice to meet you!",
   "score": 100,
   "id": 55,
   "source": "qna_chitchat_professional.tsv",
   "metadata": [   {
      "name": "editorial",
      "value": "chitchat"
   }],
   "context":    {
      "isContextOnly": false,
      "prompts": []
   }
}]}

The json above contains "output", so if you add another {"output": } before the "Answers" in the "Response" action. The json data in "Body" box of "Response" action will not match the schema you provided.

Apart from this, if you want to initialize a variable to store "Answers", you can choose the variable's type as string and set the "Value" of the variable as:

string(body('Generate_answer')?['answers'])

enter image description here

Hope it would be helpful to your problem~

Upvotes: 1

Related Questions