开发者

Send a XMPP message to an OpenFire room from the command line

开发者 https://www.devze.com 2023-02-12 15:40 出处:网络
I\'m having problems trying to send an XMPP message to a \'Room\' in our OpenFire instance. The end result is for our CruiseControl.NET build server to be able to send succe开发者_StackOverflow中文版s

I'm having problems trying to send an XMPP message to a 'Room' in our OpenFire instance. The end result is for our CruiseControl.NET build server to be able to send succe开发者_StackOverflow中文版ss/failure messages to the appropriate 'Rooms' as an additional means of notification.

I'm using the Matrix XMPP library to create a Console Application in C# using VS2010. The idea was to create a simple .exe that I can wire up to CCNet and pass a few arguments into as required.

The code below is basically the sample code from the Matrix site/documentation which I have updated to point to a room.

static void Main(string[] args)
{
    var xmppClient = new XmppClient
    {
        XmppDomain = "SERVER",
        Username = "davidc",
        Password = "*********"
    };

    xmppClient.OnRosterEnd += delegate
    {
        xmppClient.Send(new Message
        {
            To = "roomname@conference.SERVER",
            From = "davidc@SERVER",
            Type = MessageType.groupchat,
            Body = "Just Testing the XMPP SDK"
        });
    };
    xmppClient.Open();

    Console.WriteLine("Press return key to exit the application");
    Console.ReadLine();

    xmppClient.Close();
}

I can send to an individual user (changing the To and Type accordingly) without any problems but changing the code to point to a room ends in silence! Is there some additional 'handshaking' that needs to be done to address a room?

I don't really have to use C# for the solution as long as it will run on a Windows Server.


You'll want to read XEP-0045, "Multi-User Chat". You need to enter the room before sending a message to it. For a quick fix, see section 7.1.1, which shows how to join a room using a simplified (older) protocol:

<presence
    to='darkcave@chat.shakespeare.lit/thirdwitch'/>

For the newer protocol, include an extra x tag from section 7.1.2:

<presence
    to='darkcave@chat.shakespeare.lit/thirdwitch'>
  <x xmlns='http://jabber.org/protocol/muc'/>
</presence>

I don't know your library, but you'll want code something like:

xmppClient.Send(new Presence
{
    To = "roomname@conference.SERVER/mynick",
});
0

精彩评论

暂无评论...
验证码 换一张
取 消