Add info on writing plugins.
This commit is contained in:
parent
6e25d76586
commit
773970ce90
1 changed files with 32 additions and 1 deletions
33
README.md
33
README.md
|
@ -37,7 +37,7 @@ Installation
|
|||
|
||||
*Note*: At this point rtmbot is ready to run, however no plugins are configured.
|
||||
|
||||
Plugins
|
||||
Add Plugins
|
||||
-------
|
||||
|
||||
Each plugin should create a directory under ```plugins/``` with .py files for the code you would like to load. libraries can be kept in a subdirectory.
|
||||
|
@ -50,3 +50,34 @@ To install the example 'repeat' plugin
|
|||
The repeat plugin will now be loaded by the bot on startup.
|
||||
|
||||
./rtmbot.py
|
||||
|
||||
Create Plugins
|
||||
--------
|
||||
|
||||
####Incoming data
|
||||
Plugins are callback based and respond to any event sent via the rtm websocket. To act on an event, create a function definition called process_(api_method) that accepts a single arg. For example, to handle incoming messages:
|
||||
|
||||
def process_message(data):
|
||||
print data
|
||||
|
||||
This will print the incoming message json (dict) to the screen where the bot is running.
|
||||
|
||||
####Outgoing data
|
||||
Plugins can send messages back to any channel, including direct messages. This is done by appending a two item array to the outputs global array. The first item in the array is the channel ID and the second is the message text. Example that writes "hello world" when the plugin is started:
|
||||
|
||||
outputs = []
|
||||
outputs.append(["C12345667", "hello world"])
|
||||
|
||||
*Note*: you should always create the outputs array at the start of your program, i.e. ```outputs = []```
|
||||
|
||||
####Timed jobs
|
||||
Plugins can also run methods on a schedule. This allows a plugin to poll for updates or perform housekeeping during its lifetime. This is done by appending a two item array to the crontable array. The first item is the interval in seconds and the second item is the method to run. For example, this will print "hello world" every 10 seconds.
|
||||
|
||||
outputs = []
|
||||
crontable = []
|
||||
crontable.append([10, "say_hello"])
|
||||
def say_hello():
|
||||
outputs.append(["C12345667", "hello world"])
|
||||
|
||||
####Plugin misc
|
||||
The data is a plugin persists for the life of the rtmbot process. If you need persistent data, you should use something like sqlite or the python pickle libraries.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue