SYNOPSIS

        #!/usr/bin/env perl

        use 5.8.0;
        use warnings;
        use strict;

        use NetSDS::Kannel;

        my $kannel = NetSDS::Kannel->new(
                sendsms_url    => 'http://localhost:1234/sendsms',
                sendsms_user   => 'sender',
                sendsms_passwd => 'secret',
                default_smsc   => 'esme-megafon',
        );

        $res = $kannel->send(
                from     => '1234',
                to       => '380672222111',
                text     => 'Hallo there!',
                smsc     => 'emse-mts',
                priority => 3,
        );

        1;

DESCRIPTION

\*(C`NetSDS::Kannel\*(C' module provides \s-1API\s0 to Kannel \s-1SMS\s0 gateway.

To decrease innecessary problems we use a lot of predefined parameters while sending and receiving messages via Kannel \s-1HTTP\s0 \s-1API\s0. It's not so flexible as direct \s-1HTTP\s0 processing but less expensive in development time ;-)

This modules uses \s-1LWP\s0 to send messages and \s-1CGI\s0.pm to process messages from Kannel.

CLASS API

new(%params) - class constructor

Constructor creates Kannel \s-1API\s0 handler and set it's configuration. Most of these parameters may be overriden while object method calls. Admin \s-1API\s0 parameters: * admin_url - Kannel admin \s-1API\s0 \s-1URL\s0 * admin_passwd - password to admin \s-1API\s0 Sending \s-1SMS\s0 \s-1API\s0 parameters: * sendsms_url - \s-1URL\s0 of Kannel sendsms \s-1HTTP\s0 \s-1API\s0 * sendsms_user - user name for sending \s-1SMS\s0 * sendsms_passwd - password for sending \s-1SMS\s0 * dlr_url - base \s-1URL\s0 for \s-1DLR\s0 retrieving * default_smsc - default \s-1SMSC\s0 identifier for sending \s-1SMS\s0 * default_timeout - default sending \s-1TCP\s0 timeout

OBJECT METHODS

send(%parameters) - send \s-1MT\s0 \s-1SM\s0 message to Kannel

This method allows to send \s-1SMS\s0 message via Kannel \s-1SMS\s0 gateway. Parameters (mostly the same as in Kannel sendsms \s-1API\s0): * from - source address (overrides message) * to - destination address (overrides message) * text - message text (byte string) * udh - user data header (byte string) * charset - charset of text * coding - 0 for \s-1GSM\s0 03.38, 1 for binary, 2 for \s-1UCS2\s0 * smsc - target \s-1SMSC\s0 (overrides default one) * mclass - message class if necessary (0 for flash sms) * validity - \s-1TTL\s0 for \s-1MO\s0 \s-1SM\s0 in minutes * deferred - timeout for delayed delivery Example: use NetSDS::Kannel; use NetSDS::Util::Misc;

my $kannel = NetSDS::Kannel->new(...); $kannel->send_sms( from => '1234', to => '380672206770', text => 'Wake up!!!', smsc => 'nokia_modem', msgid => make_uuid, );

receive($cgi) - receive \s-1MO\s0 or \s-1DLR\s0 from \s-1CGI\s0 object

This method provides import message structure from \s-1CGI\s0 request . This method is just wrapper around \*(C`receive_mo()\*(C' and \*(C`receive_dlr()\*(C' methods. Message type (\s-1MO\s0 or \s-1DLR\s0) recognized by \*(C`type\*(C' \s-1CGI\s0 parameter that may be \*(C`mo\*(C' or \*(C`dlr\*(C'. my $cgi = CGI::Fast->new(); my %ret = $kannel->receive($cgi);

receive_mo($cgi) - import \s-1MO\s0 message from \s-1CGI\s0 object

This method provides import message structure from \s-1CGI\s0 request . Imported \s-1MO\s0 message parameters returned as hash with the following keys: * smsc - Kannel's \s-1SMSC\s0 Id * smsid - \s-1SMSC\s0 message \s-1ID\s0 * from - subscriber's \s-1MSISDN\s0 * to - service address (short code) * time - \s-1SMS\s0 receive time * unixtime \s-1SMS\s0 receive time as \s-1UNIX\s0 timestamp * text - \s-1MO\s0 \s-1SM\s0 text * bin - \s-1MO\s0 \s-1SM\s0 as binary string * udh - \s-1SMS\s0 \s-1UDH\s0 (User Data Headers) * coding - \s-1SMS\s0 encoding (0 - 7 bit \s-1GSM\s0 03.38; 2 - \s-1UCS2-BE\s0) * charset - charset of \s-1MO\s0 \s-1SM\s0 text while receiving from Kannel * binfo - \s-1SMPP\s0 \*(C`service_type\*(C' parameter for billing puroses

receive_dlr($cgi) - import message from \s-1CGI\s0 object

This method provides import message structure from \s-1CGI\s0 request . \*(C`receive_dlr\*(C' method returns hash with the following keys: * smsc - kannel \s-1SMSC\s0 id * msgid - original \s-1MT\s0 \s-1SM\s0 message id for \s-1DLR\s0 identification * smsid - \s-1SMSC\s0 message \s-1ID\s0 * from - subscriber's \s-1MSISDN\s0 (phone number) * to - service address (short code) * time - delivery time * unixtime - delivery time as \s-1UNIX\s0 timestamp * dlr - \s-1DLR\s0 state * dlrmsg - \s-1DLR\s0 message from \s-1SMSC\s0 Example: my $cgi = CGI->new();

my %dlr = $kannel->receive_dlr($cgi);

print "DLR received for MSISDN: " . $dlr{from};

make_dlr_url(%params) - prepare \s-1DLR\s0 \s-1URL\s0

This method creates \s-1URI\s0 escaped string with \s-1URL\s0 template for \s-1DLR\s0 notification. Paramters: hash (dlr_url, msgid) Returns: \s-1URI\s0 escaped \s-1DLR\s0 \s-1URL\s0

make_meta(%params) - prepare \s-1SMPP\s0 optional \s-1TLV\s0

This method creates \s-1URI\s0 escaped string with optional \s-1SMPP\s0 tag-lenght-value (\s-1TLV\s0) parameters to send them in \*(C`meta-data\*(C' \s-1CGI\s0 paramter of Kannel's \*(C`sendsms\*(C' \s-1HTTP\s0 \s-1API\s0. Format of \*(C`meta-data\*(C' parameter value: ?smpp?tag1=value1&tag2=value2&...tagN=valueN Paramters: hash of \s-1TLV\s0 pairs Returns: \s-1URI\s0 escaped string Example: my $meta = $self->make_meta( charging_id => '0', ); This will return: %3Fsmpp%3Fcharging_id%3D0

status() - retrieve Kannel status
store_status() - retrieve message queue status

Not implemented yet.

shutdown() - bring down Kannel
suspend() - switch Kannel to 'suspended' state
isolate() - switch Kannel to 'isolated' state
resume() - resume Kannel to 'online' state
restart() - whole bearerbox restart
flush_dlr() - flush queued \s-1DLR\s0 if Kannel in 'suspended' state
reload_lists() - reload black/white lists
log_level($level) - change Kannel log-level
start_smsc($smsc) - switch on \s-1SMSC\s0 connection
stop_smsc($smsc) - switch off \s-1SMSC\s0 connection
add_smsc($smsc) - add new \s-1SMSC\s0 connection
remove_smsc($smsc) - remove \s-1SMSC\s0 connection

EXAMPLES

See Nibelite kannel \s-1API\s0

RELATED TO NetSDS::Kannel…

  • NetSDS::Class::Abstract - base NetSDS class

  • http://www.kannel.org/download/1.4.3/userguide-1.4.3/userguide.html <http://www.kannel.org/download/1.4.3/userguide-1.4.3/userguide.html> - Kannel User Guide

TODO

1. Add \s-1PPG\s0 support.

2. Add \s-1OTA\s0 support.

AUTHOR

Michael Bochkaryov <[email protected]>

LICENSE

Copyright (C) 2008-2009 Net Style Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the \s-1GNU\s0 General Public License for more details.

You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, \s-1MA\s0 02111-1307 \s-1USA\s0