NetSDS::Kannel(3pm)

πŸ“¦
version 1.300 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– NetSDS::Kannel πŸ’–

okay bestie, so this is NetSDS::Kannel(3pm) β€” a User Contributed Perl Documentation page, and it's literally the Kannel SMS gateway API. yes. SMS. in perl. we love to see it 🫢


✨ NAME ✨

NetSDS::Kannel β€” Kannel SMS gateway API


🌸 SYNOPSIS 🌸

like, here's the whole vibe in one go:

#!/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;
not me noticing emse-mts in there πŸ’€ it's in the original, so it stays in the original, i don't make the rules, i just keep them exactly as they are, no cap.

πŸ¦‹ DESCRIPTION πŸ¦‹

so NetSDS::Kannel is the module that gives you an API to the Kannel SMS gateway. that's the whole thing. it's giving "i speak fluent SMS so you don't have to" πŸ’…

here's the tea: to keep you from drowning in unnecessary problems, this module comes with a lot of predefined parameters baked in for sending and receiving messages through the Kannel HTTP API. it's not as flexible as talking straight to HTTP yourself, but it's way less expensive in development time ;-) β€” pick your fighter.

and for the technical girlies: this module uses LWP to send messages, and CGI.pm to process messages coming back from Kannel. iconic combo honestly.


πŸ‘‘ CLASS API πŸ‘‘

new(%params) β€” class constructor

the constructor makes your Kannel API handler and sets its configuration up. most of these params can be overridden later when you call object methods, so don't stress too hard.

Admin API parameters:

  • admin_url β€” Kannel admin API URL
  • admin_passwd β€” password to admin API

Sending SMS API parameters:

  • sendsms_url β€” URL of Kannel sendsms HTTP API
  • sendsms_user β€” user name for sending SMS
  • sendsms_passwd β€” password for sending SMS
  • dlr_url β€” base URL for DLR retrieving
  • default_smsc β€” default SMSC identifier for sending SMS
  • default_timeout β€” default sending TCP timeout

🌈 OBJECT METHODS 🌈

send(%parameters) β€” send MT SM message to Kannel

this is the one. this method lets you send an SMS message through the Kannel SMS gateway. main character energy fr fr ✨

Parameters (mostly the same as in the Kannel sendsms API, so iykyk):

  • 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 GSM 03.38, 1 for binary, 2 for UCS2
  • smsc β€” target SMSC (overrides default one)
  • mclass β€” message class if necessary (0 for flash sms)
  • validity β€” TTL for MO SM 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 MO or DLR from CGI object

this method imports a message structure straight from a CGI request. lowkey it's just a wrapper around receive_mo() and receive_dlr() β€” it's the girl who introduces you to her two friends.

message type (MO or DLR) is recognized by the type CGI parameter, which may be mo or dlr.

my $cgi = CGI::Fast->new();
my %ret = $kannel->receive($cgi);

receive_mo($cgi) β€” import MO message from CGI object

this method imports a message structure from a CGI request.

the imported MO message parameters come back as a hash with these keys:

  • smsc β€” Kannel's SMSC Id
  • smsid β€” SMSC message ID
  • from β€” subscriber's MSISDN
  • to β€” service address (short code)
  • time β€” SMS receive time
  • unixtime β€” SMS receive time as UNIX timestamp
  • text β€” MO SM text
  • bin β€” MO SM as binary string
  • udh β€” SMS UDH (User Data Headers)
  • coding β€” SMS encoding (0 - 7 bit GSM 03.38; 2 - UCS2-BE)
  • charset β€” charset of MO SM text while receiving from Kannel
  • binfo β€” SMPP service_type parameter for billing purposes

receive_dlr($cgi) β€” import message from CGI object

this method imports a message structure from a CGI request.

receive_dlr returns a hash with these keys:

  • smsc β€” kannel SMSC id
  • msgid β€” original MT SM message id for DLR identification
  • smsid β€” SMSC message ID
  • from β€” subscriber's MSISDN (phone number)
  • to β€” service address (short code)
  • time β€” delivery time
  • unixtime β€” delivery time as UNIX timestamp
  • dlr β€” DLR state
  • dlrmsg β€” DLR message from SMSC

Example:

my $cgi = CGI->new();

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

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

make_dlr_url(%params) β€” prepare DLR URL

this method creates a URI escaped string with a URL template for DLR notification.

Parameters: hash (dlr_url, msgid)

Returns: URI escaped DLR URL


make_meta(%params) β€” prepare SMPP optional TLV

this method creates a URI escaped string with optional SMPP tag-length-value (TLV) parameters, so you can send them in the meta-data CGI parameter of Kannel's sendsms HTTP API. it's giving "packaging my little extras cute" πŸŽ€

format of the meta-data parameter value:

?smpp?tag1=value1&tag2=value2&...tagN=valueN

Parameters: hash of TLV pairs

Returns: URI escaped string

Example:

my $meta = $self->make_meta(
    charging_id => '0',
);

this will return: %3Fsmpp%3Fcharging_id%3D0


the rest of the method roster πŸ‘―

  • status() β€” retrieve Kannel status
  • store_status() β€” retrieve message queue status
not implemented yet. bestie it's a promise, not a feature 😭
  • 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 DLR if Kannel in 'suspended' state
  • reload_lists() β€” reload black/white lists
  • log_level($level) β€” change Kannel log-level
  • start_smsc($smsc) β€” switch on SMSC connection
  • stop_smsc($smsc) β€” switch off SMSC connection
  • add_smsc($smsc) β€” add new SMSC connection
  • remove_smsc($smsc) β€” remove SMSC connection

πŸ“ EXAMPLES πŸ“

see Nibelite kannel API


⭐ SEE ALSO ⭐


🧚 TODO 🧚

  1. add PPG support.
  2. add OTA support.

like, someday. we manifest 🌸


πŸ’œ AUTHOR πŸ’œ

Michael Bochkaryov <misha@rattler.kiev.ua>


πŸ“œ 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 GNU 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 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU General Public License for more details.

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


πŸ’€ yes, "WITHOUT ANY WARRANTY" is in all caps in the original too, and honestly? it deserves the drama. that's not a vibe, that's a legally binding mood. respect it.

and that's the whole page bestie!! πŸ’– this one's from perl v5.32.1, dated 2021-12-26, and it's NetSDS::Kannel(3pm) β€” go text somebody, responsibly πŸŽ€βœ¨πŸ¦‹