Git Product home page Git Product logo

xmpp-bot's Introduction

XMPP Bot

license: AGPLv3 GitHub release Build Status Coverage Status

XMPP Bot is a tiny little bot making the link between XMPP conversations and webhooks.

User ⇄ XMPP client ⇄ XMPP Server ⇄ XMPP Bot ⇄ REST API

Key features

  • Call outgoing webhook on XMPP incoming messages from user chat or group chat (Multi-user chat "MUC"),
  • Send message templates (with values to apply to variables in that template) to user or room (MUC) on incoming authorized (basic or bearer) webhook.

Installation

An Ansible role is provided, but you can also use following commands:

  • Install Node.js:

    curl -sL https://deb.nodesource.com/setup_10.x | bash -
    apt-get install -y nodejs
  • Install npm:

    npm install npm@latest -g
  • Clone repository:

    git clone https://github.com/nioc/xmpp-bot.git /usr/local/bin/xmpp-bot/
  • Install dependency:

    cd /usr/local/bin/xmpp-bot/ && npm install --production
  • Create run user (optionnal):

    useradd -r -s /bin/false xmpp-bot
    chown xmpp-bot:xmpp-bot /usr/local/bin/xmpp-bot -R
    
  • Set configuration in /lib/config/config.json (you can copy config.json.dist)

  • Add systemd service from model:

    cp docs/xmpp-bot.service /etc/systemd/system/xmpp-bot.service
  • Update systemd:

    systemctl daemon-reload
  • Start service:

    systemctl start xmpp-bot
  • Start service at boot:

    systemctl enable xmpp-bot
  • Add fail2ban filter from model (optionnal):

    cp docs/xmpp-bot.conf /etc/fail2ban/filter.d/xmpp-bot.conf

    Add the jail (/etc/fail2ban/jail.local):

    [xmpp-bot]
    enabled  = true
    port     = http,https
    filter   = xmpp-bot
    logpath  = /var/log/xmpp-bot/webhook.log
    maxretry = 3
    bantime  = 21600 ; 6 hours

Configuration

Logger

  • level log4js level (all < trace < debug < info < warn < error < fatal < mark < off)
  • file, console and stdout define log appenders (see log4js doc)

Webhooks listener

  • path and port define the listening endpoint
  • ssl define key and certificat location and port used for exposing in https, make sure that user of the process is allowed to read cert
  • users is an array of user/password for basic authentication
  • accessLog define the listener logger

XMPP Server

  • service and domain define XMPP server
  • username and password define XMPP "bot" user credentials
  • rooms list rooms (and optionnal password) where bot will listen

Incoming webhooks (list)

  • path is the webhook key:a POST request on this path will trigger corresponding action
  • action among enumeration:
    • send_xmpp_message will send message (message in request body) to destination (from request body) ; if destination is found in config.xmppServer.rooms array, message will send as a groupchat). Request exemple:

      POST /webhooks/w1 HTTP/1.1
      Host: domain.ltd:8000
      Content-Type: application/json
      Authorization: Basic dXNlcjE6cGFzczE=
      Content-Length: 70
      
      {
          "destination":"[email protected]",
          "message":"Hi, there something wrong."
      }
    • send_xmpp_template will send template with merged variables (using JMESPath) to destination (user or room if type set to chat or groupchat)

XMPP hooks (list)

  • room is the XMPP hook key: an incoming groupchat (or chat) from this room (or this user) will trigger corresponding action
  • action among enumeration:
    • outgoing_webhook will execute a request to corresponding webhook with args as webhook code

FAQ

  • XMPP server is using a self signed certificate, how can i run service? You can allow insecure TLS connections and HTTPS requests by adding Environment=NODE_TLS_REJECT_UNAUTHORIZED=0 in /usr/lib/systemd/system/xmpp-bot.service.

Credits

  • Nioc - Initial work

See also the list of contributors to this project.

This project is powered by the following components:

License

This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details

xmpp-bot's People

Contributors

nioc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xmpp-bot's Issues

[Feature] Gitea Webhooks

Is your feature request related to a problem? Please describe.
In the gitea webhook settings I cannot set a destination as body

Describe the solution you'd like
Maybe it would be possible to add a second (or more) incoming webhook(s) with a fixed destination

Additional context
The hook is working, but I get this in console:
[2024-01-22T17:11:26.262] [ERROR] default - Destination not found

connect ECONNREFUSED

Describe the bug
Hello, not sure if it's a bug but it looks like my server refuses connection to the bot and I just don't know what's the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Configure the bot credential and server/room info + certificate
  2. Start script with "node lib/server.js"
  3. Bot errors out and quits

Logs

[2023-01-20T00:08:36.041] [INFO] default - Start xmpp-bot service - version 2.2.0
[2023-01-20T00:08:36.177] [TRACE] default - Status changed to connecting
[2023-01-20T00:08:36.429] [DEBUG] default - App is started with uid: 1000
[2023-01-20T00:08:36.430] [DEBUG] default - Start HTTPS on port 8001, private key: /home/debian/sources/xmpp-bot/certs/privkey.pem, cert: /home/debian/sources/xmpp-bot/certs/fullchain.pem
[2023-01-20T00:08:36.430] [DEBUG] default - Can read private key
[2023-01-20T00:08:36.430] [DEBUG] default - Can read certificate
[2023-01-20T00:08:36.442] [INFO] default - Listening webhooks on http://localhost:8000/webhooks http://192.168.1.20:8000/webhooks http://127.0.0.1:8000/webhooks
[2023-01-20T00:08:36.442] [INFO] default - Listening webhooks on https://localhost:8001/webhooks https://192.168.1.20:8001/webhooks https://127.0.0.1:8001/webhooks
[2023-01-20T00:08:38.657] [ERROR] default - XMPP client encountered following error: connect ECONNREFUSED MYSERVER_IP_ADDRESS:5223
[2023-01-20T00:08:38.659] [WARN] default - Received 99/undefined (application is closing), disconnect from XMPP server
[2023-01-20T00:08:38.661] [DEBUG] default - Synchronize logs file

Environment (please complete the following information):

  • Operating system Debian Bullseye on WSL 1 (Windows 10 x64 full up-to-date)
  • npm version (npm -v) 8.19.2
  • Node.js version (node -v) v18.12.1
  • Code version / commit reference 2.2.0

Additional context
I'm running prosody on Debian Bullseye as well and I see no traces of login or connection attempts in logs.

[Feature]

Hi, is it possible that the bot responds with an attachment instead of plain text?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.