A comment about POE::Component::Jabber.

POE::Component::Jabber is in my opinion very good. The way version 1 handled network connections was a bit buggy, but version 2 is huge step forward and is really great.

POE::Component::Jabber gives you a flexible framework to build your XMPP client, but you will need to do a lot yourself. You are required to have read at least RFC3920 and RFC3921. In that reagrd, the documentation is very good.

For example to send a message you'd first create a POE::Filter::XML::Node object and then pass it to the output_handler event. Here's an example of how I send messages (send_message is my own event handler, but it sends to output_handler in it's last line):

package KM::POE::JabberClient; use Filter::Template; const XNode POE::Filter::XML::Node use strict; [...] sub send_message { my ($kernel, $heap, %attrs) = @_[KERNEL, HEAP, ARG0..$#_]; my $node = XNode->new('message'); my @types = qw(chat error groupchat headline normal); $attrs{'type'} = $types[0] if exists $attrs{'type'} and !grep { $attrs{'type'} eq $_ } @type +s; for my $i (qw(subject body thread)) { my $k = delete $attrs{$i}; $node->insert_tag($i)->data($k) if $k; } $node->insert_attrs([%attrs]) if %attrs; $kernel->post($heap->{'session'}, 'output_handler', $node); }

To receive messages (and other input) in your XMPP client you'd create your own event handler. It will receive a POE::Filter::XML::Node object that you can do whatever you want with. Example from my code:

sub input_hook { my ($kernel, $heap, $node) = @_[KERNEL, HEAP, ARG0]; my $name = $node->name; my $users = $heap->{'users'}; if ($name eq 'presence') { my $jid = Net::XMPP::JID->new($node->attr('from')); my $full = $jid->GetJID('full'); my $base = $jid->GetJID('base'); my $type = $node->attr('type') || 'available'; return if $full !~ /\@/; # do some stuff with tracking online/offline users etc } elsif ($name eq 'iq' and $node->attr('type') eq 'result') { my $kids = $node->get_children(); my $res = $kids->[0]; if ($res->attr('xmlns') eq 'jabber:iq:roster') { for my $kid (@{$res->get_sort_children()}) { my $jid = $kid->attr('jid'); $users->{$jid} = {} if !exists $users->{$jid}; } } } }

The above code does not handle incoming messags (since I wasn't interested in these), but read the mentioned RFC and you'll see what you'll need.

Good luck!


In reply to Re: jabber bot for monitoring a machine by kirillm
in thread jabber bot for monitoring a machine by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.