{ "info": { "author": "Josef Lange", "author_email": "josef.d.lange@me.com", "bugtrack_url": null, "classifiers": [], "description": "SlackBorg\n=========\n\nSlackBorg is a framework for semi-conversational, multi-step workflow\nSlack Bots. We're just getting started. Have an idea? File an issue.\nHave some code? Open a pull request.\n\nConcepts\n========\n\nSlackBorg has two main things you should care about, the ``@command``\ndecorator and the ``Conversation`` class.\n\n``@command``\n------------\n\n``@command`` is a decorator you place on a function you implement to\nrespond to a given command. A command can be ``multi_step``, which is to\nsay that its function is called on the given conversation each time a\nnew message comes in, until the conversation is explicitly closed. It's\nup to you how you handle a multi-step conversation. As you'll see, the\n``Conversation`` object includes all the data you need to make decisions\neach time your handler is called. If your command is not ``multi_step``,\nthe conversation is closed immediately after your handler returns.\n\n``@command`` parameters:\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n- ``match_string``: A RegEx string that you would pass into\n ``re.compile``. *Required*\n- ``flags``: Any flags from the ``re`` module you would pass into\n ``re.compile``.\n- ``multi_step``: Set to ``True`` if your command is multi-step.\n Default ``False``.\n\n``Conversation``\n----------------\n\nThe ``Conversation`` object is the sole parameter to your command\nhandler. Conversations are unique to a given user in a given channel.\nWhen a message comes in, the conversation manager checks to see if a\nconversation exists for the sending user in the channel it is posted to.\nIf it doesn't yet exist, a Conversation object is constructed and the\ncommand manager attempts to match a command to the Conversation. If it\nfinds one, its handler is called on the conversation. If a conversation\nexists, it is updated with the latest message and its command's handler\ncalled on the updated Conversation.\n\n``Conversation`` fields:\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n- ``user_id``: the sender's Slack User ID\n- ``user_data``: the sender's full Slack User Data (fetched when the\n Conversation is first created)\n- ``channel_id``: the Conversation's Slack Channel ID\n- ``channel_data``: the Conversation's full Slack Channel Data (fetched\n when the Conversation is first created -- **only set if it's a\n channel and not a DM**)\n- ``initial_message``: the message that was responsible for the\n creation of this Conversation.\n- ``messages``: the rest of the messages. *Does not include\n ``initial_message``*.\n- ``latest_message``: the most recent message.\n- ``context``: a dictionary that you can put any data you want to\n persist in the conversation across messages. This is where the magic\n is for doing a multi-step command across a conversation.\n\n``Conversation`` methods:\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n- ``say(message)``: send a message to the channel.\n- ``close()``: close the conversation.\n\nInstallation\n============\n\nRight now, I'd probably suggest spinning up a ``virtualenv`` and running\n``python setup.py develop`` inside of it.\n\nUsage\n=====\n\nWrite yourself a script to declare your commands and run your bot, like\nso:\n\n::\n\n import os\n import random\n import re\n import time\n\n from slackborg import *\n\n # Get Bot ID and API Token from env -- make sure to put these in your env!\n BOT_ID = os.environ.get('SLACK_BOT_ID')\n BOT_TOKEN = os.environ.get('SLACK_BOT_TOKEN')\n\n # Define a default response to any non-matching commands. The default default is to silently ignore the command and close the conversation.\n @default_command\n def default_cmd(conversation):\n conversation.say(\"I see, sir {}\".format(conversation.user_data['profile']['first_name']))\n\n # Define a command by a regex string, and optionally any flags you'd give the re.compile method.\n @command('hello', flags=re.IGNORECASE)\n def hello(conversation):\n conversation.say(\"Hello! I am C-3PO, human-cyborg relations!\")\n\n # By default, a command is single-step and auto-closes its conversation upon the handler returning.\n # You can override this.\n @command('sum', flags=re.IGNORECASE, multi_step=True)\n def do_sum(c):\n print c\n operands = c.context.setdefault('operands', [])\n if len(c.messages): \n if 'done' in c.latest_message.lower():\n c.say(\"The sum of {} = {}\".format(\n \" + \".join(str(o) for o in operands),\n str(sum(operands))\n )\n )\n c.close()\n else:\n try:\n operands.append(int(c.latest_message))\n c.say(\"So far: {}...\".format(\n \" + \".join(str(o) for o in operands)\n ))\n except:\n c.say(\"That input wasn't a number. Try again!\")\n else:\n c.say(\"Just enter your operands, one by one, and then type `done` when you're done!\")\n\n def main():\n borg = SlackBorg(BOT_ID, BOT_TOKEN)\n borg.run()\n\n if __name__ == '__main__':\n main()\n\n # End\n\nThanks\n======\n Some of the patterns used in this framework borrow ideologies from _lins05/slackbot, so I thank the existing developers of that library for their prior work. Perhaps we can bring these two libraries together, eventually! Or keep them separate :D\n\n.. _lins05/slackbot: https://github.com/lins05/slackbot", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/josefdlange/slackborg", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "slackborg", "package_url": "https://pypi.org/project/slackborg/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/slackborg/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/josefdlange/slackborg" }, "release_url": "https://pypi.org/project/slackborg/0.0.3/", "requires_dist": null, "requires_python": null, "summary": "A simple semi-conversational, multi-step workflow slack bot framework.", "version": "0.0.3" }, "last_serial": 2351108, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e52b9bb5b7ccaad0176c0e9715115596", "sha256": "5ab62d15a86e4640824c67123d381f618ff8ce7850a2c9204dd5edb24d98c6de" }, "downloads": -1, "filename": "slackborg-0.0.1.tar.gz", "has_sig": false, "md5_digest": "e52b9bb5b7ccaad0176c0e9715115596", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5060, "upload_time": "2016-09-19T16:01:10", "url": "https://files.pythonhosted.org/packages/df/1d/14899eedf42ff7aa6a1645780f1bd511478fec6dd321365f92ea3677f44a/slackborg-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "9bb05cbaaa25fc2b25b0d43b8c92d7a3", "sha256": "7fff64e84d14760de80b546ab28b5da56fdcb08f77447af04b74fe5fd55fa472" }, "downloads": -1, "filename": "slackborg-0.0.2.tar.gz", "has_sig": false, "md5_digest": "9bb05cbaaa25fc2b25b0d43b8c92d7a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5702, "upload_time": "2016-09-19T16:08:44", "url": "https://files.pythonhosted.org/packages/77/c6/f7806c4e98ce91c2a5cb42ad7d1e755b3bdee8fff92506c71f74caa7114e/slackborg-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "1b1ccb83db862a3dfba91bad3727b22f", "sha256": "69eafa8211b58b3f9f86a8a96b619c66f9c3440d22d347b3c4a2eb2bca3a67e4" }, "downloads": -1, "filename": "slackborg-0.0.3.tar.gz", "has_sig": false, "md5_digest": "1b1ccb83db862a3dfba91bad3727b22f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5698, "upload_time": "2016-09-19T16:17:00", "url": "https://files.pythonhosted.org/packages/07/34/6f3f8d36c26133aa776037c80cdf3ecc701c94dfc078867056c8b6ba807e/slackborg-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1b1ccb83db862a3dfba91bad3727b22f", "sha256": "69eafa8211b58b3f9f86a8a96b619c66f9c3440d22d347b3c4a2eb2bca3a67e4" }, "downloads": -1, "filename": "slackborg-0.0.3.tar.gz", "has_sig": false, "md5_digest": "1b1ccb83db862a3dfba91bad3727b22f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5698, "upload_time": "2016-09-19T16:17:00", "url": "https://files.pythonhosted.org/packages/07/34/6f3f8d36c26133aa776037c80cdf3ecc701c94dfc078867056c8b6ba807e/slackborg-0.0.3.tar.gz" } ] }