0
const manager = Manager.getInstance()
manager.chatClient.on('messageAdded', payload => {
    console.log('payload', payload) // it is correct
    console.log('payload state attributes', payload.state.attributes) 
})

Attributes are correct on chrome's console log

{
    "body": "",
    "media": null,
    "attributes": {
        "media": "https://api.twilio.com/2010-04-01/Accounts/ACfba1ba518fcc2321c11142f4041efa23/Messages/MM762e5ab98a2adde2970303db9ab6f4ba/Media/ME77ada464c9d50d6441501abf7bbd45c3",
        "mediaType": "image/jpeg"
    },
}

But with payload.state.attributes, the attributes changed to:

{
    "proxied": true
    [[Prototype]]: Object
}

console.log result screen shot

philnash
  • 70,667
  • 10
  • 60
  • 88
Ruiwei Qi
  • 11
  • 2
  • I think this needs a bit more context. I assume you are working with Flex within a Flex plugin? Can you share the actual code you are using, how you are logging that object and then how you are trying to use `payload.state.attributes`. – philnash Mar 21 '22 at 00:05
  • @philnash Yes, I'm working with Flex Plugin. Just updated the code and added a screenshot from Chrome console. – Ruiwei Qi Mar 21 '22 at 14:56
  • Thanks for the screenshot. Can you explain to me how those attributes are being set on the message? I'm trying to reproduce and I don't know how those attributes are set. Is this a chat or SMS conversation? How is the media being attached? – philnash Mar 21 '22 at 22:23
  • @philnash It is from Inbound MMS. We are using the Flex Proxy service. – Ruiwei Qi Mar 22 '22 at 14:45
  • @philnash I got the value from "attributes" now with setTimeout for 1 second. It is very weird, it seems some async set value somewhere. – Ruiwei Qi Mar 22 '22 at 19:52

1 Answers1

1

Finally, figured it out after reading the Twilio flex "source code" from "node_module". If reason of "attributes" included from "updateReasons", then we can get the { media, mediaType } from "message.state.attributes".

I cannot find this mentioned anywhere from Twilio's documents.

manager.chatClient.on('messageUpdated', ({ message, updateReasons }) => {
  console.log('message', message)
  console.log('updateReasons', updateReasons)
})
Ruiwei Qi
  • 11
  • 2
  • Are you using the [MMS plugin](https://github.com/twilio-labs/plugin-message-media)? If so, [the details](https://github.com/twilio-labs/plugin-message-media#plugin-details) do mention that Twilio Proxy doesn't support media messages, so the plugin has to monitor the proxy messages and then update the chat message with the media details. It does not tell you how to do this yourself as it is handled in the plugin's provided UI. I guess you are doing something different with the images? Glad you found a way around this at least. – philnash Mar 23 '22 at 03:42
  • 1
    @philnash I'm using the image for the browser notification for now. But my goal is to replace the messageList with my own UI. We are using the long live channels right now but it seems to have some side effects (such as we need to delete the channel sometime), so we saved all the messages and hope we can use it in our own message list or create the "pre-defined-list". Anyway, thank you very much for help me! – Ruiwei Qi Mar 23 '22 at 22:57