errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 614 forks source link

Inconsistant contract for 'RoomOccupant' / 'Identifier' #1529

Closed webpigeon closed 8 months ago

webpigeon commented 3 years ago

In order to let us help you better, please fill out the following fields as best you can:

I am...

I am running...

Issue description

The contract for an an 'Identifier' needs is poorly defined. The RoomOccupant class ( https://errbot.readthedocs.io/en/latest/_modules/errbot/backends/base.html#RoomOccupant ), only defines one method as being required (room). The description states it should return the full name (which I'm a little confused about, but I'm assuming it wants the room ID).

ErrBot core throws an exception if there isn't a person method present:

Traceback (most recent call last):
  File "/home/webpigeon/Documents/fossgalaxy/projects/errbot/test/../backends/matrix/errmatrix.py", line 296, in on_message
    await self._bot.loop.run_in_executor(None, self._bot.callback_message, msg)
  File "/usr/lib64/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/webpigeon/.local/share/virtualenvs/errbot-CvTTjbXc/lib/python3.9/site-packages/errbot/core.py", line 698, in callback_message
    if self.process_message(msg):
  File "/home/webpigeon/.local/share/virtualenvs/errbot-CvTTjbXc/lib/python3.9/site-packages/errbot/core.py", line 257, in process_message
    raise Exception(
Exception: msg.frm not an Identifier as it misses the "person" property. Class of frm : <class 'errbot.backends.errmatrix.MatrixRoomOccupant'>.

The error message states that identifiers need to have a person property, this is incorrect as the documentation also states (and implements) that rooms are Identifiers, which clearly doesn't have a person property. The identifier also doesn't have an abstract method called person or make any reference to it (but Person does).

We've used errbot for a long time and we're really impressed with what it can do, I'm more than happy to submit a PR with documentation fixes, I just don't know what the requirements are :).

So, my questions are:

nzlosh commented 3 years ago

I didn't design errbot and I agree having an abstract base class that defines nothing does make for a weak API contract. I took a look at other backends and most use multiple inheritance of Person and RoomOccupant, however this probably only makes sense in the context of how the particular backend actually functions.

I did find a couple of exceptions to the multiple inheritance:

The Identifer class was added with this commit.

Author: Guillaume Binet <gbin@google.com>
Date:   Mon Nov 9 14:42:28 2015 -0500

    Materialized Identifier and MUCIdentifier as ABC

    With type hinting on the API surface, it makes more sense now to
    materialize the Identifiers so users can autocomplete/explore them.

When committed, it had the following method: person, client, nick, aclattr, fullname.

A later commit removed all methods

commit b9ae4d06ed9668694ce5ea54580acd2f0b412c04
Author: Guillaume Binet <gbin@google.com>
Date:   Fri Mar 4 16:10:44 2016 -0800

    big rename, still some failing cases.

The methods removed from Identifier are all part of the Person class.

From the examples I've seen, I'd recommend using multiple inheritance and if that causes crashes in the plugin, try to investigate what underlying assumptions in the code aren't compatible with that backend and try work around it. I hope that helps.

webpigeon commented 3 years ago

Thanks very much, based on that I was able to get my Matrix backend working (it also has reaction support now :)).