Saluran budak

Saluran budak lebih mirip bungkus API IM, itu melampirkan pesan dari IM ke objek yang sesuai dan mengirimkannya ke saluran induk.

Meskipun kami menyarankan agar saluran budak harus sesuai dengan platform IM, akan tetapi anda dapat mencoba menyesuaikan untuk segala hal yang dapat mengirimkan informasi sebagai pesan, dan memiliki batasan daftar poin akhir untuk menyampaikan pesan ke dan dari obrolan.

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:

  • platform IM tidak membedakan antara pengguna dan bot, atau

  • bot pada platform IM bisa melakukan hal yang sama persis, jika tidak lebih, sebagai pengguna, dan bot bisa dibuat lebih mudah daripada akun pengguna.

Fitur tambahan

Saluran budak dapat menawarkan fungsi yang lebih dari apa yang EFB membutuhkan, seperti membuat kelompok, mencari teman, dll, melalui fitur tambahan.

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:

  • menjadi peka

  • hanya termasuk huruf besar, huruf kecil, dan garis bawah.

  • tidak dimulai dengan angka.

  • berada di suhu udara turun menjadi antara 1 dan 20 inklusif

  • Jadilah sesingkat dan ringkas mungkin, tapi tetap mengerti

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

Perintah pesan

Perintah pesan biasanya dikirim oleh saluran budak sehingga pengguna dapat merespon pesan tertentu yang memiliki tindakan khusus yang diperlukan.

Mungkin kasus-kasus ketika perintah pesan dapat berguna:

  • Tambahkan sebagai teman ketika kontak kartu diterima.

  • Menerima atau menolak ketika permintaan teman diterima.

  • Vote to a voting message.

Sebuah pesan anda dapat melampirkan daftar perintah, di mana masing-masing dari mereka memiliki:

  • manusia-nama,

  • a callable name,

  • a list of positional arguments (*args), and

  • a dict of keyword arguments (**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.

Pengiriman pesan

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.