Hubot XMPP
Connects Hubot to your XMPP network (including MUC
group chats), built on @xmpp/client.
Requires Hubot >= 14 and Node >= 22.11 (ESM).
Setup
npm install
Configuration
The adapter requires these environment variables:
HUBOT_XMPP_USERNAME– the bot's JID, optionally including a resource (e.g.hal8000@kosmos.org/hubot).HUBOT_XMPP_PASSWORD– the bot account's password.HUBOT_XMPP_ROOMS– comma separated list of rooms to join. Rooms requiring a password use thejid:passwordsyntax. Room passwords cannot contain,. Room names must be the full jid, e.g.dev@conference.jabber.example.org.
Optional:
HUBOT_XMPP_HOST– the host name to connect to. Only needed as an explicit override; by default the host is resolved from the JID domain.HUBOT_XMPP_PORT– the port to connect to whenHUBOT_XMPP_HOSTis set (default5222). Ignored otherwise.HUBOT_XMPP_PM_ADD_PREFIX– make commands work in private messages to the bot without the robot name/alias prefix.HUBOT_XMPP_KEEPALIVE_INTERVAL– keep-alive (XMPP ping) interval in ms (default30000).
When HUBOT_XMPP_HOST is not set, the connection host is resolved from the JID
domain using DNS SRV records (XEP-0368 / RFC 6120) and the XEP-0156 well-known
file, via @xmpp/resolve. This means the XMPP host does not need to match the
JID domain and does not need to be configured manually. The most secure
endpoint is tried first (direct TLS before STARTTLS).
Direct TLS SNI is set to the JID domain (per XEP-0368 §3 rule 6), so the certificate is verified against the domain rather than the resolved IP address. This is a workaround for the upstream xmpp.js issue until xmppjs/xmpp.js#1128 is released.
Reconnection is handled by @xmpp/client's built-in reconnect support.
Installation
Create a standalone hubot with the XMPP adapter:
mkdir -p ./my-bot
cd ./my-bot
npx -p yo -p generator-hubot -c 'yo hubot --adapter=xmpp'
See also https://hubot.github.com/docs/ .
Group chat vs private JID
The XMPP protocol does not broadcast a real user JID in group chat presence stanzas unless the server/room is configured to do so.
If you need to send a private chat in response to a group chat message, use
hubot's send method with the group chat jid and envelope.user.type = 'direct'.
hubot-xmpp will then automatically resolve the JID to a private chat JID and
private message the sender.
If you need to get the private chat JID, you can use
msg.envelope.user.privateChatJID where msg is the parameter of hubot's
route callback.
Example:
robot.respond(/talk to me$/i, msg => {
// Simply reply
msg.reply(`Hello ${msg.envelope.user.name}. Your private JID is ${msg.envelope.user.privateChatJID}`);
});
robot.respond(/talk to me in private$/i, msg => {
msg.envelope.user.type = 'direct';
msg.send(`Hey ${msg.envelope.user.name}! You told me in room ${msg.envelope.user.room} to talk to you.`);
});
Tests
npm test