<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.6.17 (Ruby 3.1.2) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ralston-mimi-matrix-message-format-00" category="info" consensus="true" submissionType="IETF" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.15.2 -->
  <front>
    <title abbrev="Matrix Message Format">Matrix Message Format</title>
    <seriesInfo name="Internet-Draft" value="draft-ralston-mimi-matrix-message-format-00"/>
    <author fullname="Travis Ralston">
      <organization>The Matrix.org Foundation C.I.C.</organization>
      <address>
        <email>travisr@matrix.org</email>
      </address>
    </author>
    <author fullname="Matthew Hodgson">
      <organization>The Matrix.org Foundation C.I.C.</organization>
      <address>
        <email>matthew@matrix.org</email>
      </address>
    </author>
    <date year="2022" month="November" day="06"/>
    <area>Applications and Real-Time</area>
    <workgroup>More Instant Messaging Interoperability</workgroup>
    <keyword>matrix</keyword>
    <keyword>mimi</keyword>
    <abstract>
      <t>This document specifies a message format using Matrix for messaging interoperability.</t>
    </abstract>
    <note removeInRFC="true">
      <name>About This Document</name>
      <t>
        The latest revision of this draft can be found at <eref target="https://turt2live.github.io/ietf-mimi-matrix-message-format/draft-ralston-mimi-matrix-message-format.html"/>.
        Status information for this document may be found at <eref target="https://datatracker.ietf.org/doc/draft-ralston-mimi-matrix-message-format/"/>.
      </t>
      <t>
        Discussion of this document takes place on the
        More Instant Messaging Interoperability Working Group mailing list (<eref target="mailto:mimi@ietf.org"/>),
        which is archived at <eref target="https://mailarchive.ietf.org/arch/browse/mimi/"/>.
        Subscribe at <eref target="https://www.ietf.org/mailman/listinfo/mimi/"/>.
      </t>
      <t>Source for this draft and an issue tracker can be found at
        <eref target="https://github.com/turt2live/ietf-mimi-matrix-message-format"/>.</t>
    </note>
  </front>
  <middle>
    <section anchor="introduction">
      <name>Introduction</name>
      <t>Interoperable instant messaging requires a common format for all participants to contribute to the conversation or state of the room.
Matrix is an open protocol for interoperable, decentralized, secure communication, and alongside its existing transport functionality
[TODO: Link to draft-ralston-mimi-matrix-transport], defines a rich taxonomy of arbitrarily extensible payloads of
information called "events" to carry information between machines and users, which may in turn
be layered over end-to-end encryption.  Matrix events have been designed for interoperability from the outset between
heterogenous messaging platforms, and define a real-world highest-common denominator set of message types,
including:</t>
      <ul spacing="normal">
        <li>Instant messages (plain &amp; rich text)</li>
        <li>End-to-end encrypted payloads</li>
        <li>File transfer</li>
        <li>Reactions (emoji, textual, image-based)</li>
        <li>Edits</li>
        <li>Replies</li>
        <li>Deletions</li>
        <li>Stickers</li>
        <li>Custom emoji</li>
        <li>Voice messages</li>
        <li>Polls</li>
        <li>Static location share</li>
        <li>Live location share (ephemeral)</li>
        <li>Live location share (persistent)</li>
        <li>Spoiler text</li>
        <li>Threaded messages</li>
        <li>Typing notifications</li>
        <li>Read receipts</li>
        <li>Read-up-to markers</li>
        <li>Presence</li>
        <li>1:1 VoIP signalling</li>
        <li>Multiparty VoIP signalling</li>
      </ul>
      <t>Matrix events are extensible, and proposals exist for additional event formats ranging from attaching 3D world geometry
to conversations (for openly standardized metaverse communication) through to transferring healthcare data (FHIR).</t>
    </section>
    <section anchor="matrix-events">
      <name>Matrix Events</name>
      <t>Events are JSON objects which by default follow the formal schemas defined in the Matrix Client Server API <xref target="MxEvents"/>,
also available as JSON Schema definitions <xref target="MxEventsSchema"/>.  Events are extensible and may contain additional off-schema
prefixed fields, or use prefixed event types not yet defined in the spec.  Events then get augumented
and signed by the server before being forwarded to other servers/users in the room.</t>
      <t>These JSON objects have a few key fields:</t>
      <ul spacing="normal">
        <li>
          <tt>type</tt>: A string the client can use to determine how to render the event. This is reverse-DNS namespaced, with <tt>m.</tt> as
a privileged prefix for event types formally adopted and defined within the Matrix specification.</li>
        <li>
          <tt>sender</tt>: The user ID (<tt>@alice:example.org</tt>) which sent the event.</li>
        <li>
          <tt>room_id</tt>: The room ID (<tt>!room:example.org</tt>) for where the event was sent.</li>
        <li>
          <tt>content</tt>: Type-specific JSON object.</li>
        <li>Other fields (TODO: define these in detail when more relevant to the doc).</li>
      </ul>
      <t>Under MSC1767 <xref target="MSC1767"/> (a spec change proposal in the existing Matrix open standard ecosystem), callers can combine
together multiple event types to provide fallback representations of an event, to provide backwards compatibility when
rendering unknown event types.</t>
      <t>An example of a simple text message would be:</t>
      <sourcecode type="json"><![CDATA[
{
    "type": "m.message",
    "content": {
        "m.text": "i am a fish",
        "m.html": "i am a <strong>fish</strong>"
    }
}
]]></sourcecode>
      <t>This can be made more complex if the sender chooses to mix in other mimetypes:</t>
      <sourcecode type="json"><![CDATA[
{
  "type": "m.message",
  "content": {
    "m.message": [
        { "mimetype": "text/html", "body": "i am a <strong>fish</strong>" },
        { "mimetype": "text/plain", "body": "i am a fish" },
        { "mimetype": "application/vnd.exampleorg.message+html", "body": "<content>i am a <strong>fish</strong></content>" }
    ]
  }
}
]]></sourcecode>
      <t>To demonstrate extensibility, a file upload <xref target="MSC3551"/> might look like:</t>
      <sourcecode type="json"><![CDATA[
{
  "type": "m.file",
  "content": {
    "m.text": "Upload: foo.pdf https://example.org/_matrix/media/v3/download/example.org/abcd1234 (12 KB)",
    "m.file": {
      "url": "mxc://example.org/abcd1234",
      "name": "foo.pdf",
      "mimetype": "application/pdf",
      "size": 12345
    }
  }
}
]]></sourcecode>
      <t>In this example, clients which do not understand <tt>m.file</tt> but do understand <tt>m.text</tt> (or <tt>m.message</tt>) would show just the plain text instead of
a download button. The alternative to falling back would be to hide the unrenderable event, causing the conversation history to be fragmented:
this has clear negative consequences on user experience. Instead, by defining a fallback mechanism the user is still able to participate
in the conversation, though might need to ask for more information. It is expected that the "base types" (text messages, images, videos, and
generic files) would be supported by all clients to ensure there are sufficient building blocks for future extensibility.</t>
      <t>A more complete use-case for extensible events is described by "MSC3381: Polls" <xref target="MSC3381"/> - clients which do not yet have support for polls
can present their users with text fallback for the question and the question asker can manually tally up "improper" responses (if those users
simply sent text messages in response to the question). Clients which do support polls would simply show the poll and its question/options for
the user to click on - their response would be sent to the room as a (deliberately) unrenderable event for other clients to tally up automatically.</t>
    </section>
    <section anchor="encryption">
      <name>Encryption</name>
      <t>Matrix has specified an encryption algorithm for events called Megolm, however for the purposes of MIMI it would be desirable to adopt MLS
<xref target="I-D.ietf-mls-protocol"/> instead. Some bookkeeping changes are required to support MLS in a decentralized environment like Matrix: those
are currently defined by <xref target="DMLS"/>.</t>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>TODO Security. Future drafts should consider the encryption aspects in particular.</t>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <reference anchor="MxEvents" target="https://spec.matrix.org/v1.4/client-server-api/#events">
          <front>
            <title>Events | Client-Server API</title>
            <author>
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2022"/>
          </front>
        </reference>
        <reference anchor="MxEventsSchema" target="https://github.com/matrix-org/matrix-spec/tree/main/data/event-schemas/schema">
          <front>
            <title>Matrix Event JSON Schemas</title>
            <author>
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2022"/>
          </front>
        </reference>
        <reference anchor="MSC1767" target="https://github.com/matrix-org/matrix-spec-proposals/blob/d6046d8402e7a3c7a4fcbc9da16ea9bad5968992/proposals/1767-extensible-events.md">
          <front>
            <title>Extensible event types &amp; fallback in Matrix (v2)</title>
            <author initials="M." surname="Hodgson" fullname="Matthew Hodgson">
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <author initials="T." surname="Ralston" fullname="Travis Ralston">
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2022"/>
          </front>
        </reference>
        <reference anchor="MSC3551" target="https://github.com/matrix-org/matrix-spec-proposals/blob/5bf2118e8ac873e7845b1eedde8dd7bc187ed673/proposals/3551-extensible-events-files.md">
          <front>
            <title>Extensible Events - Files</title>
            <author initials="T." surname="Ralston" fullname="Travis Ralston">
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2021"/>
          </front>
        </reference>
        <reference anchor="I-D.ietf-mls-protocol">
          <front>
            <title>The Messaging Layer Security (MLS) Protocol</title>
            <author fullname="Richard Barnes" initials="R." surname="Barnes">
              <organization>Cisco</organization>
            </author>
            <author fullname="Benjamin Beurdouche" initials="B." surname="Beurdouche">
              <organization>Inria &amp; Mozilla</organization>
            </author>
            <author fullname="Raphael Robert" initials="R." surname="Robert">
         </author>
            <author fullname="Jon Millican" initials="J." surname="Millican">
              <organization>Facebook</organization>
            </author>
            <author fullname="Emad Omara" initials="E." surname="Omara">
              <organization>Google</organization>
            </author>
            <author fullname="Katriel Cohn-Gordon" initials="K." surname="Cohn-Gordon">
              <organization>University of Oxford</organization>
            </author>
            <date day="11" month="July" year="2022"/>
            <abstract>
              <t>   Messaging applications are increasingly making use of end-to-end
   security mechanisms to ensure that messages are only accessible to
   the communicating endpoints, and not to any servers involved in
   delivering messages.  Establishing keys to provide such protections
   is challenging for group chat settings, in which more than two
   clients need to agree on a key but may not be online at the same
   time.  In this document, we specify a key establishment protocol that
   provides efficient asynchronous group key establishment with forward
   secrecy and post-compromise security for groups in size ranging from
   two to thousands.

              </t>
            </abstract>
          </front>
          <seriesInfo name="Internet-Draft" value="draft-ietf-mls-protocol-16"/>
        </reference>
      </references>
      <references>
        <name>Informative References</name>
        <reference anchor="MSC3381" target="https://github.com/matrix-org/matrix-spec-proposals/blob/95fdc44b904d2b4d2f227db99050e539e43f3509/proposals/3381-polls.md">
          <front>
            <title>Polls (mk II)</title>
            <author initials="T." surname="Ralston" fullname="Travis Ralston">
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2022"/>
          </front>
        </reference>
        <reference anchor="DMLS" target="https://gitlab.matrix.org/matrix-org/mls-ts/-/blob/dd57bc25f6145ddedfb6d193f6baebf5133db7ed/decentralised.org">
          <front>
            <title>Decentralised MLS</title>
            <author initials="H." surname="Chathi" fullname="Hubert Chathi">
              <organization>The Matrix.org Foundation C.I.C.</organization>
            </author>
            <date year="2021"/>
          </front>
          <seriesInfo name="Web" value="https://gitlab.matrix.org/matrix-org/mls-ts/-/blob/dd57bc25f6145ddedfb6d193f6baebf5133db7ed/decentralised.org"/>
        </reference>
      </references>
    </references>
    <section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>TODO acknowledge.</t>
    </section>
  </back>
  <!-- ##markdown-source:
H4sIAAAAAAAAA8VabXPkNBL+7l8hhioq4cYzmbxnao9i2exC7gi7tQnHB4oi
sq0Za2NbxpKTDLnw2+/pluxxks2yHNQdBcmMLbX69emnFeI4jpx2hZqL0al0
jb4Rp8pauVTilWlK6UaRTJJGXT39PpVOLU2zmgtdLUwUZSatZAmBWSMXLm5k
YZ2p4lKXOi5ZRFx6EfGCRcRbW5Ftk1Jbq03lVjX2nrw8fyXEpwKbDY7WVaZq
hR+VG43F6OT5V/hlGnx6e/5qFFVtmahmHmVQZR6lprKqsq2dC9e0KoLuO5Fs
lISg53VdaGiMg6yQVSbeKlnE57pUo+jaNJfLxrQ12WoaJU4q62TlgsW6WuKJ
U42pVSMTXWi3GkWXaoV92TwSsfDW8ScYG12pqoU6QvxhoUJ4L4x+gEq05GuS
QM9LqQs8J/lfauUWE9Ms6bls0hzPc+dqO59OaRk90ldq0i2b0oNp0phrq6Yk
YEobl9rlbYKtrm3cdoENU9rwgXDRrgKOtm5wYL974gVOtPk9OdOPzY9J7spi
FEWydblpyNPQQIhFWxQ+0c4beaWteOsl8UvYKyv9KwcaC3IlfPaSI5C5bZXx
K/FicjJ5MeEtyvvWsbDmy7Jf//hAyHK5uhbfmGxp//SJpZc2PDGq2HL4k/Ln
9OYlcsnZOe9yslkq+L5zva1VOlnvnV7NJrvTtN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