Streams are file transfers. It can be used to store documents, index them, send generated content on the fly etc.
10.1. Waiting for incoming file transfers¶
The bot can be sent files from the users. You only have to implement the
callback_stream() method on your plugin to be notified for new incoming file
Note: not all backends supports this, check if it has been correctly implemented from the backend itself.
For example, getting the initiator of the transfer and the content, see
more info about the various fields.
from errbot import BotPlugin, botcmd class PluginExample(BotPlugin): def callback_stream(self, stream): self.send(stream.identifier, "File request from :" + str(stream.identifier)) stream.accept() self.send(stream.identifier, "Content:" + str(stream.fsource.read()))
10.2. Sending a file to a user or a room¶
You can use
send_stream_request() to initiate a transfer:
stream = self.send_stream_request(msg.frm, open('/tmp/myfile.zip', 'r'), name='bills.zip', stream_type='application/zip')
The returned stream object can be used to monitor the progress of the transfer with stream.status, stream.transfered etc...
Stream for more details.