Debian Codegraph @

docs/user_guide/plugin_development/streams.rst

raw
1 Streams
2 =======
3
4 Streams are file transfers. It can be used to store documents, index them, send generated content on the fly etc.
5
6 Waiting for incoming file transfers
7 -----------------------------------
8
9 The bot can be sent files from the users. You only have to implement the
10 :func:`~errbot.botplugin.BotPlugin.callback_stream` method on your plugin to be notified for new incoming file
11 transfer requests.
12
13 Note: not all backends supports this, check if it has been correctly implemented from the backend itself.
14
15 For example, getting the initiator of the transfer and the content, see :class:`~errbot.backends.base.Stream` for
16 more info about the various fields.
17
18 .. code-block:: python
19
20 from errbot import BotPlugin, botcmd
21
22 class PluginExample(BotPlugin):
23
24 def callback_stream(self, stream):
25 self.send(stream.identifier, "File request from :" + str(stream.identifier))
26 stream.accept()
27 self.send(stream.identifier, "Content:" + str(stream.fsource.read()))
28
29
30 Sending a file to a user or a room
31 ----------------------------------
32
33
34 You can use :func:`~errbot.botplugin.BotPlugin.send_stream_request` to initiate a transfer:
35
36 .. code-block:: python
37
38 stream = self.send_stream_request(msg.frm, open('/tmp/myfile.zip', 'r'), name='bills.zip', stream_type='application/zip')
39
40 The returned stream object can be used to monitor the progress of the transfer with `stream.status`, `stream.transfered` etc...
41 See :class:`~errbot.backends.base.Stream` for more details.
42