0

flex.Actions.addListener accepts an event and passes an object into the Function, as detailed here:

Add an Action after a Task is accepted

console.logging the object just returns: [object Object] and JSON.stringify of the object returns: TypeError: Converting circular structure to JSON.

What is a good method to understand the structure of the object and the information that is available to me when facing the above?

Alan
  • 10,465
  • 2
  • 8
  • 9
  • Are you referring to the `payload` in the code example in the docs? It might be clearer if you put the exact sample code you're using to get both the `[object Object]` and the TypeError – Brian Thompson Jul 21 '22 at 15:40
  • So within the Functions, a couple objects are being passed it. I ended up just using intellisense, some sample code I found and these links were quite helpful: https://www.twilio.com/docs/flex/developer/ui/manager and https://assets.flex.twilio.com/docs/releases/flex-ui/2.0.0-beta.1/ and https://twilio.github.io/twilio-taskrouter.js/Worker.html – Alan Jul 21 '22 at 18:25
  • I just ran this exact example though and I'm not seeing what you're describing. I'm seeing the correct object in the console. To see `[object Object]` in a console.log is very strange, but in an `alert` it's very much expected. Are you 100% sure you were console logging and not alerting? – Brian Thompson Jul 21 '22 at 19:12
  • Yes, very sure. Using node v14.19.3. I can try again later this evening. – Alan Jul 21 '22 at 20:29
  • so in the template Flex Plug in, the code is like below. You can create a template Twilio Flex Plugin via: `twilio flex:plugins:create --flexui2` ``` async init(flex, manager) { console.log(`***Console Log of flex parameter: ${flex}`); console.log(`***Console Log of manager parameter: ${manager}`); ``` The console shows: twilio-flex.unbundled-react.min.js:1566 ***Console Log of flex parameter: [object Object] twilio-flex.unbundled-react.min.js:1566 ***Console Log of manager parameter: [object Object] twilio-flex.unbundled-react.min.js:1566 Manager: ready to laun – Alan Jul 21 '22 at 20:40
  • It really is the same behavior with the other example I posted above. I believe because it is just a complex object? – Alan Jul 21 '22 at 20:40
  • Yep, I see your problem now. That's why I was trying to get the actual code you were using. You're taking the parameter object and converting it to a string by using the template literal syntax. If you just pass it as a second parameter to `console.log` I bet you'll see it work. `console.log('***Console Log of flex parameter:', flex)` – Brian Thompson Jul 21 '22 at 20:52
  • 1
    See https://stackoverflow.com/questions/46146860/javascript-template-strings-dont-pretty-print-objects – Brian Thompson Jul 21 '22 at 20:53
  • 1
    Thanks @BrianThompson! That was it and I learned something new! – Alan Jul 21 '22 at 21:03

0 Answers0