3

I'm wondering if I can attach media to a Twilio Chat message. I'm a bit confused with Twilio docs on this:

  1. The Help Center's Programmable Chat file support for sending messages says it's not supported.
    Looks like this is outdated?
  2. The Programmable Chat's API Reference, "Channels and Messages" section says:

    Today, a message is just a string of text. In the future, this may expand to include other media types, like images and binary data.

    Also outdated?

  3. This StackOverflow answer says it's possible to send multimedia messages, at least for JavaScript. Looks like the same is possible for iOS with the TCHMessageOptions's withMediaStream:contentType:defaultFilename:onStarted:onProgress:onCompleted: method.
  4. [Aside question] Using the method above, looks like I can create a multimedia message, but can I also set custom attributes?

Could you please clarify?

Thank you!

Nikolay Mamaev
  • 1,474
  • 1
  • 12
  • 21

1 Answers1

3

Twilio developer evangelist here.

Attaching media to messages in Twilio Programmable Chat is now supported in beta. It seems that some of the documentation is a little outdated, but the page with the code and explanations you are looking for is here: https://www.twilio.com/docs/api/chat/guides/media-support.

As for sending custom attributes, each message has an attributes property that you can use to send arbitrary JSON.

I'm working to correct the misleading documentation now. Thanks for pointing it out!

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Could you please let me know how can we send image as blob in sendMessage method. Basically, in chat we are allowing the user to upload new image as well as re send the existing image in the chat. For new image we are send as formData method, for sending existing image I will have only the image base64 value. Please guide me how can we implement. Thanks. – Sankar Jul 17 '18 at 06:36
  • If you have a blob then you can attach it as form data too. If you have base64 then [convert it to a blob and attach](https://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata/5100158). – philnash Jul 17 '18 at 06:41
  • can you please confirm is this method correct. var url = $("#chatQuesImage").attr('src'); var blob = dataURLtoBlob(url); var fd = new FormData(document.forms[0]); fd.append("file", blob); myChatData.sendMessage(fd); – Sankar Jul 17 '18 at 06:58
  • I don't know! Why not try it and see. – philnash Jul 17 '18 at 06:59
  • This seems like more that we can deal with in the comments of another answer. I'd recommend you open a new question, add the code you've tried and what the results and any errors were. – philnash Jul 17 '18 at 07:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176110/discussion-between-sankar-and-philnash). – Sankar Jul 17 '18 at 07:38
  • @philnash how to remove badge when user seen message in swift? i search a lot in dcoumentation. is it possible to do with `TCHChannel`? – AbecedarioPoint Aug 13 '18 at 11:44
  • @philnash Is this feature still in beta? Where can I find instructions for installing the beta? What is the beta CDN URL? – Ryan Warner Nov 11 '19 at 22:46
  • 1
    According to [the documentation media support in chat is still beta](https://www.twilio.com/docs/chat/media-support). However you don't need to anything special to install it. The latest version of the SDKs will support it. You can read more about [what beta means for Twilio here](https://support.twilio.com/hc/en-us/articles/115002413087-Twilio-Beta-Product-Support). – philnash Nov 11 '19 at 22:49