Debian Codegraph @

docs/user_guide/backend_development/index.rst

raw
1 [Advanced] Backend development
2 ==============================
3
4 A backend is the glue code to connect Errbot to a chatting service.
5 Starting with Errbot 2.3.0, backends can be developed out of the main repository.
6 This documentation is there to guide you making a new backend for a chatting
7 service but is also interesting to understand more core concepts of Errbot.
8
9 It is important to understand the core concepts of Errbot before
10 starting to work on a backend.
11
12 Architecture
13 ------------
14
15 Backends are just a specialization of the bot, they are what
16 is instantiated as the bot and are the entry point of the bot.
17
18 Following this logic a backend must inherit from
19 :class:`~errbot.errBot.ErrBot`.
20
21 :class:`~errbot.errBot.ErrBot` inherits itself from
22 :class:`~errbot.backends.base.Backend`. This is where you can
23 find what Errbot is expecting from backend.
24
25 You'll see a series of methods simply throwing the exception
26 :class:`NotImplementedError`.
27 Those are the one you need to implement to fill up the blanks.
28
29 Identifiers
30 -----------
31
32 Every backend have a very specific way of addressing who, where
33 and how to speak to somebody.
34
35 Lifecycle: identifiers are either created internally by the backend
36 or externally by the plugins from
37 :func:`~errbot.backends.base.Backend.build_identifier`.
38
39 There are 2 types of identifiers:
40
41 - a person
42 - a person in a chatroom
43
44
45 Identifier for a person
46 -----------------------
47
48 It is important to note that for some backends you can infer what
49 a person is from what a person in a chatroom is, but for privacy
50 reason you cannot on some backends ie. you can send a private
51 message to a person in a chatroom but if the person leaves the room
52 you have no way of knowing how to contact her/him personally.
53
54 Backends must implement a specific Identifier class that matches
55 their way of identifying those.
56
57 For example Slack has a notion of userid and channeid you can find
58 in the :class:`~errbot.backends.slack.SlackIdentifier` which is
59 completely opaque to ErrBot itself.
60
61 But you need to implement a mapping from those private parameters
62 to those properties:
63
64 - person: this needs to be a string that identifies a person.
65 This should be enough info for the backend to contact this person.
66 This should be a *secure* and sure way to identify somebody.
67 - client: this will identify optionally as a string additional
68 information or channel from where this person is sending a message.
69 For example, some backends open a one to one room to chat, or some
70 backends identifies the current peripheral from which the person is
71 sending a message from (mobile, web, ...)
72
73 Some of those strings are completely unreadable for humans ie. `U00234FBE`
74 for a person. So you need to provide more human readable info:
75
76 - nick: this would be the short name refering to that person. ie. `gbin`
77 - displayName: (optionally) this would give for example a full name
78 ie. `Guillaume Binet`. This is often found in professional chatting services.
79
80
81 Identifier for a person in a chatroom
82 -------------------------------------
83
84 This is simply an Identifier with an added property: room.
85 The string representation of room should give a chatroom identifier (see below).
86
87 See for example :class:`~errbot.backends.slack.SlackMUCIdentifier`
88
89 Chatrooms / MUCRooms
90 --------------------
91
92 In order to implement the various MUC related APIs you'll find from
93 :class:`~errbot.backends.base.Backend`, you'll need to implement a Room class.
94 To help guide you, you can inherit from :class:`~errbot.backends.base.MUCRoom`
95 and fill up the blanks from the NotImplementedError.
96
97 Lifecycle: Those are created either internally by the backend or externally
98 through :func:`~errbot.backends.base.Backend.join_room` from a string identifier.