diff --git a/README.md b/README.md index eb621fe..00ce0b6 100644 --- a/README.md +++ b/README.md @@ -89,5 +89,18 @@ Plugins can also run methods on a schedule. This allows a plugin to poll for upd ####Plugin misc 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. +####Direct API Calls +You can directly call the Slack web API in your plugins by allowing the following import: + + from client import client + +You can also rename the client on import so it can be easily referenced like shown below: + + from client import client as sc + +Direct API calls can be called in your plugins in the following form: + + sc.api_call("API.method", "parameters") + ####Todo: Some rtm data should be handled upstream, such as channel and user creation. These should create the proper objects on-the-fly. diff --git a/client.py b/client.py index bbf9314..dcb7f5d 100644 --- a/client.py +++ b/client.py @@ -1,10 +1,10 @@ from slackclient import SlackClient from rtmbot import RtmBot -client = None +slack_client = None def init(config): global client bot = RtmBot(config) - client = bot.slack_client + slack_client = bot.slack_client return bot diff --git a/docs/example-plugins/directAPIcall.py b/docs/example-plugins/directAPIcall.py index 0ddebd5..30d82a0 100644 --- a/docs/example-plugins/directAPIcall.py +++ b/docs/example-plugins/directAPIcall.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -from client import client as sc +from client import slack_client as sc for user in sc.api_call("users.list")["members"]: print(user["name"], user["id"])