Skip to main content

XMPP bots for humans

Project description

xbotlib

PyPI version Build Status

XMPP bots for humans

status: experimental

A friendly lightweight wrapper around slixmpp for writing XMPP bots in Python. The goal is to make writing and running XMPP bots easy and fun. xbotlib is a single file implementation which can easily be understood and extended. It provides a small API surface which reflects the slixmpp way of doing things.

Install

$ pip install xbotlib

Example

Put the following in a echo.py file. xbotlib provides a number of example bots which you can use to get moving fast and try things out.

from xbotlib import EchoBot

EchotBot()

And then python echo.py. You will be asked a few questions like which account details your bot will be using.

This will generate a bot.conf file in the same working directory for further use.

Here's the code for the EchoBot.

class EchoBot(Bot):
    """Gives back what you sent it.

    In group chats, it responds to the following format.

    echobot:foo
    """
    def react(self, message):
        if message.type == "chat":
            self.reply(message.body, to=message.sender)

        if message.type == "groupchat" and "echobot" in message.body:
            _, to_echo = message.body.split(":")
            self.reply(to_echo, room=message.room)

All examples

  • EchoBot: Sends back what you sent it
  • WhisperBot: Pseudo-anonymous whispering in group chats

See xbotlib.py for all example bots.

API Reference

When writing your own bot, you always sub-classes the Bot class provided from xbotlib. All underling functions can be extended. For example, if you want to enable more plugins or add different functionality. If something feels awkward then please raise a ticket for that. Seamlessness is still a bitch but we're trying anyway.

Bot.react(message)

A function which you define in your bot implementation in order to respond to chat messages. You can respond to both direct messages and group chat messages in this function by checking the message.type which can be either chat or groupchat.

Arguments:

  • message: sent message and metadata (see message reference below)

Bot.reply(body, to=None, room=None)

Send back a response to a direct chat message.

Arguments:

  • body: the message to send
  • to: which user account to reply to (direct chat)
  • room: which room to reply to (group chat)

SimpleMessage

A simple message format. This is the type that you work with when your function accepts a message argument.

Attributes:

  • body: the body of the message
  • sender: the user the message came from
  • room: the room the message came from
  • receiver: the receiver of the message
  • nickname: the nickname of the sender
  • type: the type of message (chat or groupchat)

Configure your bot

Using the environment

You can pass the --no-input option to your script invocation (e.g. python bot.py --no-input).

xbotlib will try to read the following configuration values from the environment.

  • XBOT_JID: The username of the bot account
  • XBOT_PASSWORD: The password of the bot account
  • XBOT_ROOM: The room that the bot can join
  • XBOT_NICK: The nickname that the bot uses

Roadmap

See the issue tracker.

Changes

See the CHANGELOG.md.

License

See the LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xbotlib-0.5.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

xbotlib-0.5.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file xbotlib-0.5.0.tar.gz.

File metadata

  • Download URL: xbotlib-0.5.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/4.19.0-13-amd64

File hashes

Hashes for xbotlib-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d52673477871266247ab8ff7dc2eaea938c24680790666ec209a239d2b983934
MD5 df4392abf231809578890841f8518f49
BLAKE2b-256 4fc4b3f845872c834549a7cf1886b67213a416470b5aba813e8ba1897998245e

See more details on using hashes here.

File details

Details for the file xbotlib-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: xbotlib-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/4.19.0-13-amd64

File hashes

Hashes for xbotlib-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe5940ab54237c4261566ed1a721838168399318295b36c33cffb4902a01ff5d
MD5 6d15e7811ecf5b0a2db5bfedff4297dd
BLAKE2b-256 2ee5c5b91b79bec3382c51fa5e7526f2d92435b497357701a93722d17924d806

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page