JABBER-QUERYBOT(1p)
๐ JABBER-QUERYBOT ๐
okay bestie, grab a strawberry ๐ โ this is the Perl User Contributed documentation for jabber-querybot(1p) and it's literally the blueprint for building your own lil modular Perl Jabber bot. no cap, it's giving "small bot, one job, done beautifully". โจ
๐ธ NAME ๐ธ
jabber-querybot โ a modular perl jabber bot ๐
๐ DESCRIPTION ๐
So here's the vibe: jabber-querybot connects a jabber account and justโฆ waits for messages. ๐ When a message comes in, it forwards it to your very own self-programmed modul. Then whatever string your module returns? jabber-querybot sends it right back to the jabber sender. Iconic behavior, honestly.
It's designed to be re-usable and to make it easy to write small Jabber bots that do one thing and do it well. A simple concept with a lot of examples and experiences are implemented. fr fr. ๐
- Create a jabber account on a jabber-server around ๐
- Create a bot application:
cd examples
cp Querymodule.pm /etc/jabber-querybot/Mybot.pm
cd /etc/jabber-querybot
ln -s Mybot.pm Querymodule.pm
Modify login parameters to your jabber-bot-account ๐
vim Mybot.pm
our $hostname = "swissjabber.ch";
our $user = "";
our $password = "";
our $ident = "Testbot";
our $bot_admin = "\@swissjabber.ch";
our $port = "5222";
our $timeout = "5";
our $service_name = "$user\@$hostname";
our $bot_description = "Bot help title
Bot description";
For each jabber message, jabber-querybot will execute sub run_query, that you can write here your application. ๐ซถ
You can control how your jabber response will be:
error= error message stanzapresence= error as presence stanzaignore= ignore message
โจ OPTIONS โจ
jabber-querybot has a lot of variables which you can easy modify for what you need:
๐ฆ querystatus ๐ฆ
$querystatus = [ 0 | 1 ]
0= Bot will not proceed any incoming jabber messages.1= Bot will proceed incoming messages.
๐ penalty_status ๐
If the bot has too much workload, it goes to penalty status and wait some time until his status change back to normal. ๐ฎโ๐จ
$timer_reconnect_default = 21600
Every 21600 seconds (6 hours) the bot will shutdown automatically, wait 10 seconds and starting up again.
$timer_auto_query = 0
If you set in your module this variable to 60, the bot will every 60 seconds call the function run_auto_query() which you may use for several things. ๐ฅ
๐ System load ๐
If your systems load is >=6, this bot will shutdown the jabber connection and check every 10 seconds systems load. If load <=2, bot will start over. ๐ง
๐ EXAMPLES ๐
/usr/share/doc/jabber-querybot/examples/Testbot.pm
๐ FILES ๐
/etc/jabber-querybot/Querymodule.pm
/usr/bin/jabber-querybot
โญ RESOURCES โญ
http://github.com/micressor/jabber-querybot/
๐ METHODS ๐
๐ธ InMessage() ๐ธ
An incoming jabber message to the bot will hook this function.
- Read parameters of incoming stanza
- Decode utf8 string
- increment timer overload and do not process message if bot is overloaded.
- Ignore message if it is from myself
- Be sure, that it is not a message from another transport
- Check any systemcommands for the bot
- If the bot has sleeping status, change it to work
- We process only normal text or chat type jabber messages
- And now we give the real text string which was incoming to the bot via
run_query(). - If
run_query()say us'ignorewe do a log entry and do not answer via jabber to the user. - If
run_query()says'errorwe send a jabber error stanza with the status message fromrun_query()back to the user. - If there was no error, we update the statistic vars and send the answer from
run_query()back to the jabber user.
๐ฆ connect_server() ๐ฆ
This function connects to the jabber server with the given credentials from Querymodule.pm.
Set the call back functions. This functions will be executed if a message of the types <message/> <iq/> or <presence/> are incoming.
๐ Stop() ๐
Shutdown jabber connection and exit main program ๐
๐ disconnect_server() ๐
Only disconnect from the jabber-server.
๐ reconnect_server() ๐
Reconnect and create a log entry.
๐ InIQ() ๐
We do not proceed any iq (information query), this is only for statisic.
๐ง InPresence() ๐ง
- Increment timer overload
- Do not process message if we are overloaded
penalty_handler().
We have a problem in Net::Jabber. An incoming message with a ` in resource blocks the bot. We will hotfix that for the moment. ๐ญ
A subscription type subscribe is incoming. Send subscribed tho the user and say hello ;)
- Send presence to user
- Remove subscription if a user remove this bot from his roster
๐ sendPresence() ๐
Send presence information to user
โญ systemcommands() โญ
- If user type
'!helpsend a help instruction to the user - Send statistic information to the user if he types
'!status - Is it a bot command?
- Is the bot command from the bot admin? If not, send "not allowed"
'!shutdownwill shutdown your bot via jabber invoke.'!query offturn off queries'!query onturn on queries
๐ get_barejid() ๐
Remove resource id from a jabber id.
๐ calcualte_stats() ๐
Calculate message statistics
๐ซ jabber_set_presence() ๐ซ
Set new presence if we have another presence status or we have set the force flag (for transport presence).
๐ jabber_send_message() ๐
This function send all jabber messages which are outgoing from the jabber-querybot.
๐ซถ set_wakeup_mode() ๐ซถ
Set jabber presence via jabber_set_presence()
๐ฅ penalty_handler() ๐ฅ
This function checks if the bot is overloaded with incoming messages and reject if it is. Two times that's ok so 2:1 because while in main.
Bot admin got every time an answer.
๐ฆ jabber_add_footer() ๐ฆ
Add footer to the processed message.
๐ calcualte_elapsed_time() ๐
Calculate elapsed worktime for a query
โจ sendError() โจ
sendError($message, $from, $to, 404, "text");
๐ธ system_load_check() ๐ธ
- Calculate system load
- If load is too high shutdown bot.
- If load is ok, starting up bot
๐ connect_bot() ๐
Connect bot and initialize all timers.
๐ check_before_start() ๐
Check configuration variables in Querybotmodule.pm and give answer if anything does not match or is missing.
๐ COPYRIGHT AND LICENSE ๐
Copyright (C) 2009-2012 Marco Balmer <marco@balmer.name>
The Debian packaging is licensed under the GPL, see /usr/share/common-licenses/GPL-3'.
and that's the whole page bestie, you ate that ๐ซถ this was perl v5.40.1, dated 2026-05-08 โ go build ur lil bot, mwah ๐โจ
๐ฆ where this page comes from
- ubuntu stonking: jabber-querybot 0.1.0+git20160217.1338677-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms