microsoft / BotFramework-Composer

Dialog creation and management for Microsoft Bot Framework Applications
https://docs.microsoft.com/en-us/composer/
MIT License
860 stars 366 forks source link

Bot Framework Composer: Error Accessing Nested JSON Properties #9692

Closed aymiee closed 4 months ago

aymiee commented 5 months ago

Describe the bug

When attempting to access the 'data' property from a JSON response in Bot Framework Composer using turn.results.text, the path returns empty. Direct access and expressions such as ${json(turn.results.text.content.data)} lead to an "Operation returned an invalid status code 'BadRequest'" error.

My web app use to return the response in 'message' field and I was able to retrieve it via : ${turn.results.content.data.message} Recently, I started getting "Operation returned an invalid status code 'BadRequest'". The structure of ${turn.results} has changed to:

{ "lgType": "Activity", "text": { "statusCode": 200, "reasonPhrase": "OK", "headers": { "Date": "Mon, 22 Jan 2024 04:58:15 GMT", "Server": "gunicorn" }, "content": { "data": "How can I assist you today? If you have any IT-related queries, need information from the company data, or have compliance-related questions, feel free to ask!" } } }

Attempts to access the data with ${getProperty(turn.results.text.content, 'data')} and ${turn.results.text.content.data} have been unsuccessful resulting in Operation returned an invalid status code 'BadRequest'

Additionally, ${turn.results.text.content} and ${turn.results.text} are returning empty.

Version

Version: 2.1.2 Electron: 8.2.4 Chrome: 80.0.3987.165 NodeJS: 12.13.0 V8: 8.0.426.27-electron.0

Browser

OS

To Reproduce

Steps to reproduce the behavior:

  1. Send an HTTP request and store the result in turn.results.
  2. Attempt to access a nested JSON property turn.results.text.content.data,
  3. Receive an empty response or an error.

Expected behavior

Screenshots

Additional context

The exact JSON response structure is as follows:


{ 
  "lgType": "Activity", 
  "text": { 
    "statusCode": 200, 
    "reasonPhrase": "OK", 
    "headers": { 
      "Date": "Mon, 22 Jan 2024 04:31:39 GMT", 
      "Server": "gunicorn" 
    }, 
    "content": { 
      "data": "It seems like there might have been a typo in your message. How can I assist you today?..." 
    } 
  } 
}
dmvtech commented 5 months ago

@aymiee

dmvtech commented 5 months ago

I am able to reproduce. Investigating further.

dmvtech commented 5 months ago

Likely related: https://stackoverflow.com/questions/77847235/inconsistent-display-of-array-property-in-bot-framework-composer-direct-vs-con/

dmvtech commented 5 months ago

Also confirmed:

aymiee commented 5 months ago

Thanks, I was told on Microsoft tech community that the issue was an update in the template engine used by the Bot Framework Composer. I have since updated my flask backend to retrieve the content from the text key.

I also modified my Flask app to not encapsulate the response in a JSON object with 'data' as the key since the Bot Framework Composer already uses 'content' in the JSON structure. I can now access value via ${turn.results.content}

{ "lgType": "Activity", "text": { "statusCode": 200, "reasonPhrase": "OK", "headers": { "Date": "Mon, 22 Jan 2024 04:58:15 GMT", "Server": "gunicorn" }, "content": { "How can I assist you today? If you have any IT-related queries, need information from the company data, or have compliance-related questions, feel free to ask!" } } }

ceciliaavila commented 4 months ago

Closing as the fix was merged in the SDK repository.