melo / codebits

Presentations and projects done at SAPO Codebits

This URL has Read+Write access

codebits / 2008 / xmpp-hands-on / bots / http2xmpp / http2xmpp-send.pl
100755 43 lines (34 sloc) 0.778 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env perl
 
use strict;
use warnings;
use LWP::UserAgent;
use Getopt::Long;
use Encode 'encode';
 
my %cfg;
my $ok = GetOptions(\%cfg, "to=s", "body=s", "xml=s" );
usage() unless $ok;
 
binmode(\*STDIN, ':utf8');
unless ($cfg{to}) {
  print "Type the destination JID:\n" if -t \*STDIN;
  while (! $cfg{to}) {
    my $to = <>;
    chomp($to);
    $cfg{to} = $to;
  }
}
 
unless ($cfg{body}) {
  print "Type the message to send, CTRL-D to send, CTRL-C to abort\n" if -t \*STDIN;
  local $/;
  $cfg{body} = <>;
}
 
while (my ($k, $v) = each %cfg) {
  $cfg{$k} = encode('utf8', $v);
}
 
my $ua = LWP::UserAgent->new;
my $r = $ua->post('http://127.0.0.1:3001/send', \%cfg);
 
 
sub usage {
  print STDERR <<EOU;
Usage: http2xmpp-send.pl --to=JID --message=MESSAGE
EOU
 
  exit(1);
}