class ehforwarderbot.EFBMiddleware(instance_id: Optional[str] = None)[source]

Middleware class.


Unique ID of the middleware. Convention of IDs is specified in Packaging and Publish. This ID will be appended with its instance ID when available.


Human-readable name of the middleware.


The instance ID if available.

__init__(instance_id: Optional[str] = None)[source]

Initialize the middleware. Inherited initializer must call the “super init” method at the beginning.

Parameters:instance_id – Instance ID of the middleware.
get_extra_functions() → Dict[str, Callable][source]

Get a list of additional features

Returns:A dict of methods marked as additional features. Method can be called with get_extra_functions()["methodName"]().
Return type:Dict[str, Callable]
process_message(message: EFBMsg) → Optional[EFBMsg][source]

Process a message with middleware

Parameters:message (EFBMsg) – Message object to process
Returns:Processed message or None if discarded.
Return type:Optional[EFBMsg]
process_status(status: EFBStatus) → Optional[EFBStatus][source]

Process a status update with middleware

Parameters:status (EFBStatus) – Message object to process
Returns:Processed status or None if discarded.
Return type:Optional[EFBStatus]

About Middleware ID

With the introduction of instance IDs, it is required to use the self.middleware_id or equivalent instead of any hard-coded ID or constants while referring to the middleware ID (e.g. while retrieving the path to the configuration files, etc).

Receive commands with user through Master Channel

Despite we do not limit how users can perform actions to your middleware, there are 2 common ways to do it through a master channel.

Capture messages

If the action is chat-specific, you might want to catch messages that match specific pattern. Try to make the pattern easy to type but unique enough so that you don’t accidentally catch messages that were meant to sent to the chat.

You may also construct a virtual sender of type “System” to give response to the user.

“Additional features”

If the action is not specific to any chat, but to the system as a whole, we have provided the same command line-like interface as in slave channels to middlewares as well. Details are available at Additional features.