BotFramework-Composer icon indicating copy to clipboard operation
BotFramework-Composer copied to clipboard

Bot Framework Composer: Error Accessing Nested JSON Properties

Open aymiee opened this issue 1 year ago • 5 comments

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

  • [x] Electron distribution
  • [ ] Chrome
  • [ ] Safari
  • [ ] Firefox
  • [ ] Edge

OS

  • [ ] macOS
  • [x] Windows
  • [ ] Ubuntu

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?..." 
    } 
  } 
}


aymiee avatar Jan 22 '24 16:01 aymiee

@aymiee

  • What version of the SDK is the bot running?
  • Was there an update/migration to a newer version for this when it started happening?

dmvtech avatar Jan 23 '24 23:01 dmvtech

I am able to reproduce. Investigating further.

dmvtech avatar Jan 24 '24 00:01 dmvtech

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

dmvtech avatar Jan 24 '24 00:01 dmvtech

Also confirmed:

  • Doing something like Results: ${turn.results} will display correctly without the lgType property.
  • Not related to channel (same behavior in Emulator, Test in Web Chat, Web Chat, Teams).

dmvtech avatar Jan 24 '24 00:01 dmvtech

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!" } } }

aymiee avatar Jan 24 '24 00:01 aymiee

Closing as the fix was merged in the SDK repository.

ceciliaavila avatar Mar 05 '24 15:03 ceciliaavila