Canales esclavos

Los canales esclavos son mas que un simple empaquetado sobre los API de un IM, el anexa los mensajes provenientes de un IM dentro de un objeto y los envía al canal maestro.

Aunque nosotros sugerimos que los canales esclavos deben coincidir con una plataforma de IM, puedes tratar de modelarlo como cualquier elemento que pueda enviar información como mensajes y además cuenta con una lista de terminales a los cuales enviar mensajes desde y hasta los chats.

In most of the cases, slave channels SHOULD be identified as one single user from the IM platform, instead of a bot. You should only use a bot for slave channels when:

  • la plataforma IM no reconoce ninguna diferencia entre un usuario y un bot o

  • los bots en la plataforma IM pueden hacer exactamente las mismas cosas o incluso más que como usuarios, además los bots pueden ser creados de manera más sencilla que las cuentas de usuario.

Características adicionales

Los canales esclavos pueden ofrecer más funciones de las que EFB requiere, tales como la creación de grupos, la búsqueda de amigos, etc, por medio de las características adicionales.

Such features are accessed by the user in a CLI-like style. An “additional feature” method MUST only take one string parameter aside from self, and wrap it with extra() decorator. The extra decorator takes 2 arguments: name – a short name of the feature, and desc – a description of the feature with its usage.

desc SHOULD describe what the feature does and how to use it. It’s more like the help text for an CLI program. Since method of invoking the feature depends on the implementation of the master channel, you SHOULD use "{function_name}" as its name in desc, and master channel will replace it with respective name depend on their implementation.

The method MUST in the end return a string, which will be shown to the user as its result, or None to notify the master channel there will be further interaction happen. Depending on the functionality of the feature, it may be just a simple success message, or a long chunk of results.

The callable MUST NOT raise any exception to its caller. Any exceptions occurred within should be expected and processed.

Callable name of such methods has a more strict standard than a normal Python 3 identifier name, for compatibility reason. An additional feature callable name MUST:

  • sensible a letras mayúsculas y minúsculas

  • incluir solo letras mayúsculas y minúsculas, dígitos y guion bajo.

  • does not start with a digit.

  • estar dentro de un tamaño entre 1 y 20 inclusivo

  • be as short and concise as possible, but keep understandable

It can be expressed in a regular expression as:

^[A-Za-z][A-Za-z0-9_]{0,19}$

An example is as follows:

@extra(name="Echo",
       desc="Return back the same string from input.\n"
            "Usage:\n"
            "    {function_name} text")
def echo(self, arguments: str = "") -> str:
    return arguments

Comandos de mensaje

Los comandos de mensajes usualmente son enviados por los canales esclavos de manera que los usuarios puedan responder a ciertos mensajes que requieran acciones específicas.

Possible cases when message commands could be useful:

  • Add as friends when a contact card is received.

  • Accept or decline when a friend request is received.

  • Vote to a voting message.

Un mensaje puede ser adjuntado con una list de comandos, en el que cada uno de ellos tiene:

  • un nombre legible

  • un nombre de invocación,

  • una list de argumentos posicionales (*args) y

  • un dict de argumentos por palabras claves (**kwargs)

When the User clicked the button, the corresponding method of your channel will be called with provided arguments.

Note that all such methods MUST return a str as a respond to the action from user, and they MUST NOT raise any exception to its caller. Any exceptions occurred within MUST be expected and processed.

Entrega de mensajes

Slave channels SHOULD deliver all messages that the IM provides, including what the User sent outside of this channel. But it SHOULD NOT deliver message sent from the master channel again back to the master channel as a new message.

Implementation details

See SlaveChannel.