2014-08-16 00:09:55 +02:00
Group Chat Invitations
======================
2018-03-12 15:34:23 +01:00
[Back ](index.md )
2015-02-26 18:41:17 +01:00
The group chat invitation extension is used to invite other users to a
2014-08-16 00:09:55 +02:00
group chat room.
* Inviting Other Users
* Listen for Invitations
**XEP related:** N/A -- this protocol is outdated now that the Multi-User Chat (MUC) XEP is available ([XEP-45](http://www.xmpp.org/extensions/xep-0045.html)). However, most existing clients still use this older protocol. Once MUC support becomes more widespread, this API may be deprecated.
2020-07-18 12:55:26 +02:00
**XEP related:** Now there is support for XEP-0249: Direct MUC Invitations.
2014-08-16 00:09:55 +02:00
Inviting Other Users
--------------------
To use the GroupChatInvitation packet extension to invite another user to a
group chat room, address a new message to the user and set the room name
appropriately, as in the following code example:
```
2018-04-01 16:12:31 +02:00
Message message = new Message("user@chat.example.com", "Join me for a group chat!");
2014-08-16 00:09:55 +02:00
message.addExtension(new GroupChatInvitation("room@chat.example.com"));
2015-02-26 18:41:17 +01:00
con.sendStanza(message);
2014-08-16 00:09:55 +02:00
```
The XML generated for the invitation portion of the code above would be:
```
< x xmlns = "jabber:x:conference" jid = "room@chat.example.com" / >
```
Listening for Invitations
-------------------------
2015-02-26 18:41:17 +01:00
To listen for group chat invitations, use a StanzaExtensionFilter for the `x`
2014-08-16 00:09:55 +02:00
element name and `jabber:x:conference` namespace, as in the following code
example:
```
2015-02-26 18:41:17 +01:00
StanzaFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference");
2014-08-16 00:09:55 +02:00
// Create a packet collector or packet listeners using the filter...
```