You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ The repeat plugin will now be loaded by the bot on startup. Run `rtmbot` from co
115
115
Create Plugins
116
116
--------
117
117
118
-
####Incoming data
118
+
####Incoming data
119
119
All events from the RTM websocket are sent to the registered plugins. To act on an event, create a function definition, inside your Plugin class, called process_(api_method) that accepts a single arg for data. For example, to handle incoming messages:
120
120
121
121
def process_message(self, data):
@@ -129,17 +129,17 @@ For a list of all possible API Methods, look here: https://api.slack.com/rtm
129
129
130
130
Note: If you're using Python 2.x, the incoming data should be a unicode string, be careful you don't coerce it into a normal str object as it will cause errors on output. You can add `from __future__ import unicode_literals` to your plugin file to avoid this.
131
131
132
-
####Outgoing data
132
+
####Outgoing data
133
133
134
-
#####RTM Output
134
+
#####RTM Output
135
135
Plugins can send messages back to any channel or direct message. This is done by appending a two item array to the Plugin's output array (```myPluginInstance.output```). The first item in the array is the channel or DM ID and the second is the message text. Example that writes "hello world" when the plugin is started:
136
136
137
137
class myPlugin(Plugin):
138
138
139
139
def process_message(self, data):
140
140
self.outputs.append(["C12345667", "hello world"])
141
141
142
-
#####SlackClient Web API Output
142
+
#####SlackClient Web API Output
143
143
Plugins also have access to the connected SlackClient instance for more complex output (or to fetch data you may need).
144
144
145
145
def process_message(self, data):
@@ -148,7 +148,7 @@ Plugins also have access to the connected SlackClient instance for more complex
148
148
username="pybot", icon_emoji=":robot_face:"
149
149
150
150
151
-
####Timed jobs
151
+
####Timed jobs
152
152
Plugins can also run methods on a schedule. This allows a plugin to poll for updates or perform housekeeping during its lifetime. Jobs define a run() method and return any outputs to be sent to channels. They also have access to a SlackClient instance that allows them to make calls to the Slack Web API.
153
153
154
154
For example, this will print "hello world" every 10 seconds. You can output multiple messages two the same or different channels by passing multiple pairs of [Channel, Message] combos.
@@ -169,5 +169,5 @@ For example, this will print "hello world" every 10 seconds. You can output mult
169
169
self.jobs.append(job)
170
170
171
171
172
-
####Plugin misc
172
+
####Plugin misc
173
173
The data within 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.
0 commit comments