сегодня задался аналогичным вопросом, в итоге написал себе такой вариант решения:
#!/usr/bin/perl
use Net::XMPP;
use Encode;
my $to='my@domain.ru';
my $server='domain.ru';
my $port=5222;
my $user='test';
my $password="mypassword";
my $resource="home";
my $connectiontype="tcpip";
my $ssl=0;
my $tls=1;
my $debugLevel = 0;
my $client = Net::XMPP::Client->new(debuglevel => $debugLevel);
# Определяем обработчики событий
$client->SetCallBacks(onauth => \&onAuth,);
$client->SetMessageCallBacks(#normal =>\&messageNormalCB,
chat =>\&messageChatCB);
my $status = $client->Execute(
hostname => $server,
port => $port,
connectiontype => $connectiontype,
ssl => $ssl,
tls => $tls,
username => $user,
password => $password,
resource => $resource);
if (!(defined($status))) {
print "ERROR: XMPP connection failed.\n";
print "($!)\n";
exit(0);
}
sub onAuth {
$client->PresenceSend(show => 'online', priority => 10);
print "online\n";
}
sub messageChatCB {
my ($sid, $mes) = @_;
my $sender = $mes->GetFrom();
my $body = encode('cp866', $mes->GetBody());
#my $thread = $mes->GetThread();
print "$sender\n$body\n\n";
print encode('cp866', decode('utf-8', 'Что скажем?'))."\n";
my $mes = <STDIN>;
my $text = decode('cp866', $mes);
$client->MessageSend(
to => $to,
#resource => $resource,
#subject => "Subj",
type => "chat",
body => $text);
}