Skip to content

# Setting vCards / Avatars for MUC rooms

ejabberd supports the ability to set vCard for MUC rooms. One of the most common use case is to be able to define an avatar for your own MUC room.

## How does it work?

To be allowed to set vCard for a given room, you need to be owner of that room.

To set up vCard avatar for your MUC room, you first need to make sure you convert your avatar image to base64 encoding, so that you can pass it on XMPP stream.

If you want to convert it manually from command line, you can use `base64` tool. For example:

    base64 muc_logo.png > muc_logo.b64

However, when coding the client, you can more likely directly do the proper image base64 encoding in your code.

## Setting up MUC vCard

To set the MUC vCard, you can send a vcard-temp set request, as defined in XEP-0054: vcard-temp, but directly addressed to your MUC room. For example, assuming my room id is `test@conference.localhost`:

    <iq id='set1'
        type='set'
        to='test@conference.localhost'>
    <vCard xmlns='vcard-temp'>
        <PHOTO>
          <TYPE>image/png</TYPE>
          <BINVAL>

          </BINVAL>
        </PHOTO>
    </vCard>
    </iq>

Please, note that you have to set the mime type of the image properly to help the client displaying it.

You can of course add other fields to the vCard if needed.

After that IQ `set` stanza, the server will reply with success:

    <iq from="test@conference.localhost"
        type="result"
        to="owner@localhost/r"
        id="set1">
     <vCard xmlns="vcard-temp"/>
    </iq>

The MUC room also broadcasts a notification about non-privacy related configuration change to users that are currently in the room:

    <message from="test@conference.localhost"
             type="groupchat"
             to="owner@localhost/r"
             id="17095969463368094420">
     <x xmlns="http://jabber.org/protocol/muc#user">
      <status code="104"/>
     </x>
    </message>

## Retrieving a MUC room vCard

Any user can retrieve the MUC vCard but sending a vcard-temp get IQ to the room itself:

    <iq to='test@conference.localhost'
        id='get1'
        type='get'>
      <vCard xmlns='vcard-temp'/>
    </iq>

Server will reply by sending back the vCard:

    <iq from="test@conference.localhost"
        type="result"
        to="user@localhost/r"
        id="get1">
     <vCard xmlns="vcard-temp">
        <PHOTO>
          <TYPE>image/png</TYPE>
          <BINVAL>

          </BINVAL>
        </PHOTO>
     </vCard>
    </iq>