{"action":"created","issue":{"url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/57","repository_url":"https://api.github.com/repos/slackhq/python-rtmbot","labels_url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/57/comments","events_url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/57/events","html_url":"https://github.com/slackhq/python-rtmbot/pull/57","id":169786050,"number":57,"title":"Adding API Access to Plugin Context (Updated)","user":{"login":"philipyun103","id":12608723,"avatar_url":"https://avatars.githubusercontent.com/u/12608723?v=3","gravatar_id":"","url":"https://api.github.com/users/philipyun103","html_url":"https://github.com/philipyun103","followers_url":"https://api.github.com/users/philipyun103/followers","following_url":"https://api.github.com/users/philipyun103/following{/other_user}","gists_url":"https://api.github.com/users/philipyun103/gists{/gist_id}","starred_url":"https://api.github.com/users/philipyun103/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipyun103/subscriptions","organizations_url":"https://api.github.com/users/philipyun103/orgs","repos_url":"https://api.github.com/users/philipyun103/repos","events_url":"https://api.github.com/users/philipyun103/events{/privacy}","received_events_url":"https://api.github.com/users/philipyun103/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-08-07T08:24:36Z","updated_at":"2016-08-09T18:09:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/slackhq/python-rtmbot/pulls/57","html_url":"https://github.com/slackhq/python-rtmbot/pull/57","diff_url":"https://github.com/slackhq/python-rtmbot/pull/57.diff","patch_url":"https://github.com/slackhq/python-rtmbot/pull/57.patch"},"body":"* [X] I've read and understood the [Contributing guidelines](./CONTRIBUTING.md) and have done my best effort to follow them.\r\n* [X] I've read and agree to the [Code of Conduct](./CODE_OF_CONDUCT.md).\r\n* [x] I've been mindful about doing atomic commits, adding documentation to my changes, not refactoring too much.\r\n* [X] I've a descriptive title and added any useful information for the reviewer. Where appropriate, I've attached a screenshot and/or screencast (gif preferrably).\r\n* [X] I've written tests to cover the new code and functionality included in this PR.\r\n* [X] I've read, agree to, and signed the [Contributor License Agreement (CLA)](https://docs.google.com/a/slack-corp.com/forms/d/1q_w8rlJG_x_xJOoSUMNl7R35rkpA7N6pUkKhfHHMD9c/viewform).\r\n\r\n#### PR Summary\r\nAdds the ability to call the API directly within the plugin context.  The concept was adapted from PR #20 written by @zbarahal.  Few differences differentiate between their implementation and mine.  His requires slightly heavier adjustments to the RtmBot object class definition.  Mine only requires two changes in the definition.  Additionally mine is compatible and ready to merge with the current master\r\n\r\nNotable changes:\r\n\r\n- the line in the `RtmBot.connect()` method that instantiates the slack_client instance has been moved to the `__init__` method. \r\n- `import os` and adds `os.getcwd()` to `sys.path` in order for plugins to be able to import newly added file, client.py\r\n- instantiate a global variable, `slack_client` which can be access directly within plugins to make direct Web API calls.\r\n\r\n\r\n#### Related Issues\r\ncould potentially fix and close issues #29 #48 #49 and #50 because of the ability to format messages with direct API calls.\r\n\r\n#### Test strategy\r\nCreated a sample plugin that calls from the API instance, and prints out each user and their user ID.  This can be found in docs/example-plugin/directAPIcall.py"},"comment":{"url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/comments/238639927","html_url":"https://github.com/slackhq/python-rtmbot/pull/57#issuecomment-238639927","issue_url":"https://api.github.com/repos/slackhq/python-rtmbot/issues/57","id":238639927,"user":{"login":"jammons","id":113554,"avatar_url":"https://avatars.githubusercontent.com/u/113554?v=3","gravatar_id":"","url":"https://api.github.com/users/jammons","html_url":"https://github.com/jammons","followers_url":"https://api.github.com/users/jammons/followers","following_url":"https://api.github.com/users/jammons/following{/other_user}","gists_url":"https://api.github.com/users/jammons/gists{/gist_id}","starred_url":"https://api.github.com/users/jammons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jammons/subscriptions","organizations_url":"https://api.github.com/users/jammons/orgs","repos_url":"https://api.github.com/users/jammons/repos","events_url":"https://api.github.com/users/jammons/events{/privacy}","received_events_url":"https://api.github.com/users/jammons/received_events","type":"User","site_admin":false},"created_at":"2016-08-09T18:09:01Z","updated_at":"2016-08-09T18:09:01Z","body":"Sure!\r\n\r\nI'm thinking it'll work something like this:\r\n- user will pip install rtmbot\r\n- user creates their plugin, inheriting from a Plugin abstract base class\r\n- user adds the path to their Plugin in the config file\r\n- in core.py we look at the path and search for anything with Plugin in the name and try to do something like this:\r\n```\r\nfor plugin_path in config.paths:\r\n                self.bot_plugins.append(import_string(plugin_path)(client))\r\n```\r\n\r\nIt's a bit of work to do and some departure from the current way of doing things, but I think that will work and shouldn't be any more complicated than the current way of doing it if it's well documented.\r\n\r\nThoughts @philipyun103?"}}
{"actor":{"display_login":"jammons"}}