def create_endpoints(plugin: SlackPlugin): plugin.on_command("/lunch", slash_lunch, wait=False) plugin.on_command("/repeat", slash_repeat, wait=False) plugin.on_command("/report", slash_report, wait=False) plugin.on_command("/roll", slash_roll, wait=False) plugin.on_command("/mentor", slash_mentor, wait=False) plugin.on_command("/mentor-volunteer", slash_mentor_volunteer, wait=False)
async def test_start_find_bot_id(self, aiohttp_server, find_bot_id_query): bot = SirBot() bot.load_plugin( SlackPlugin(token="foo", verify="bar", bot_user_id="baz")) bot["plugins"]["slack"].api.query = find_bot_id_query await aiohttp_server(bot) assert bot["plugins"]["slack"].bot_id == "B00000000"
def bot(): b = SirBot() slack = SlackPlugin(token='token', verify='supersecuretoken', bot_user_id='bot_user_id', bot_id='bot_id') b.load_plugin(slack) return b
async def test_register_admin_message_no_admin(self, caplog): async def handler(): pass bot = SirBot() bot.load_plugin(SlackPlugin(token='foo', verify='bar', bot_user_id='baz', bot_id='boo')) bot['plugins']['slack'].on_message('hello', handler, admin=True) assert 'Slack admins ids are not set. Admin limited endpoint will not work.' in caplog.text
async def slack_bot(bot): slack = SlackPlugin( token='token', verify='supersecuretoken', bot_user_id='bot_user_id', bot_id='bot_id', ) endpoints.slack.create_endpoints(slack) bot.load_plugin(slack)
def slack_bot(bot: SirBot): slack = SlackPlugin( token="token", verify="supersecuretoken", bot_user_id="bot_user_id", bot_id="bot_id", ) endpoints.slack.create_endpoints(slack) bot.load_plugin(slack) return bot
async def bot_signing(): b = SirBot() b.load_plugin( SlackPlugin( token="foo", signing_secret="sharedsigningkey", bot_user_id="baz", bot_id="boo", admins=["aaa", "bbb"], )) return b
async def bot(): b = SirBot() b.load_plugin( SlackPlugin( token="foo", verify="supersecuretoken", bot_user_id="baz", bot_id="boo", admins=["aaa", "bbb"], )) return b
async def test_register_admin_message_no_admin(self, caplog): async def handler(): pass bot = SirBot() bot.load_plugin( SlackPlugin(token="foo", verify="bar", bot_user_id="baz", bot_id="boo")) bot["plugins"]["slack"].on_message("hello", handler, admin=True) assert ( "Slack admins ids are not set. Admin limited endpoint will not work." in caplog.text)
async def bot(loop) -> SirBot: b = SirBot() slack = SlackPlugin( token='token', verify='supersecuretoken', bot_user_id='bot_user_id', bot_id='bot_id', ) airtable = AirtablePlugin() endpoints.slack.create_endpoints(slack) b.load_plugin(slack) b.load_plugin(airtable) return b
async def bot(loop) -> SirBot: b = SirBot() slack = SlackPlugin( token="token", verify="supersecuretoken", bot_user_id="bot_user_id", bot_id="bot_id", ) airtable = AirtablePlugin() endpoints.slack.create_endpoints(slack) api = APIPlugin() endpoints.api.create_endpoints(api) b.load_plugin(slack) b.load_plugin(airtable) b.load_plugin(api) return b
def create_endpoints(plugin: SlackPlugin): # simple actions that can be used in multiple scenarios plugin.on_action("claimed", claimed, name="claimed", wait=False) plugin.on_action("claimed", reset_claim, name="reset_claim", wait=False) plugin.on_block("submission", delete_message, action_id="cancel_btn", wait=False) # new member interactive actions plugin.on_action("resource_buttons", resource_buttons, wait=False) plugin.on_action("greeted", member_greeted, name="greeted", wait=False) plugin.on_action("greeted", reset_greet, name="reset_greet", wait=False) plugin.on_action("messaged", member_messaged, name="messaged", wait=False) plugin.on_action("messaged", reset_message, name="reset_message", wait=False) plugin.on_action("suggestion", open_suggestion, wait=False) plugin.on_action("suggestion_modal", post_suggestion, wait=False) # reporting related interactive actions plugin.on_action("report_message", open_report_dialog, wait=False) plugin.on_action("report_dialog", send_report, wait=False) # mentorship related interactive actions plugin.on_block( "mentor_service", set_requested_service, wait=False, action_id="mentor_service_select", ) plugin.on_block("skillset", add_skillset, action_id="skillset_select", wait=False) plugin.on_block("clear_skillsets", clear_skillsets, action_id="clear_skillsets_btn", wait=False) plugin.on_block("mentor", set_requested_mentor, action_id="mentor_select", wait=False) plugin.on_block("comments", open_details_dialog, action_id="comments_btn", wait=False) plugin.on_block("mentor_details_submit", mentor_details_submit, wait=False) plugin.on_block("affiliation", set_group, action_id="affiliation_select", wait=False) plugin.on_block("submission", mentor_request_submit, action_id="submit_mentor_btn", wait=False) # mentor volunteer actions plugin.on_block("volunteer_skillset", add_volunteer_skillset, wait=False) plugin.on_block("clear_volunteer_skillsets", clear_volunteer_skillsets, wait=False) plugin.on_block( "submission", submit_mentor_volunteer, action_id="submit_mentor_volunteer_btn", wait=False, ) # mentorship claims plugin.on_action("claim_mentee", claim_mentee, wait=False) plugin.on_action("reset_claim_mentee", claim_mentee, wait=False)
def create_endpoints(plugin: SlackPlugin): plugin.on_command("/here", slash_here, wait=False) plugin.on_command("/lunch", slash_lunch, wait=False) plugin.on_command("/repeat", slash_repeat, wait=False) plugin.on_command("/report", slash_report, wait=False) plugin.on_command("/ticket", slash_ticket, wait=False) plugin.on_command("/roll", slash_roll, wait=False) plugin.on_command("/mentor", slash_mentor, wait=False)
yaml.load(log_configfile.read(), Loader=yaml.SafeLoader)) except Exception as e: logging.basicConfig(level=logging.DEBUG) logger.exception(e) if "SENTRY_DSN" in os.environ: sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], release=os.environ.get("VERSION", "1.0.0"), environment=os.environ.get("ENVIRONMENT", "production"), integrations=[AioHttpIntegration()], ) bot = SirBot() slack = SlackPlugin(**slack_configs) endpoints.slack.create_endpoints(slack) bot.load_plugin(slack) admin_configs = dict(**slack_configs) admin_token = os.environ.get("APP_ADMIN_OAUTH_TOKEN", "FAKE_ADMIN_TOKEN") if admin_token: admin_configs["token"] = admin_token admin_slack = SlackPlugin(**admin_configs) bot.load_plugin(admin_slack, name="admin_slack") airtable = AirtablePlugin() endpoints.airtable.create_endpoints(airtable) bot.load_plugin(airtable) api_plugin = APIPlugin()
async def test_start_no_bot_user_id(self, caplog): SlackPlugin(token="foo", verify="bar", bot_id="boo", admins=["aaa", "bbb"]) assert "`SLACK_BOT_USER_ID` not set" in caplog.text
if __name__ == "__main__": try: with open( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../logging.yml")) as log_configfile: logging.config.dictConfig(yaml.load(log_configfile.read())) except Exception as e: logging.basicConfig(level=logging.DEBUG) logger.exception(e) if "SENTRY_DSN" in os.environ: make_sentry_logger() bot = SirBot() slack = SlackPlugin() endpoints.slack.create_endpoints(slack) bot.load_plugin(slack) airtable = AirtablePlugin() endpoints.airtable.create_endpoints(airtable) bot.load_plugin(airtable) # Add route to respond to AWS health check bot.router.add_get("/health", lambda request: Response(status=200)) logging.getLogger('aiohttp.access').setLevel(logging.WARNING) bot.start(host=HOST, port=PORT, print=False)
if __name__ == "__main__": try: with open( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../logging.yml") ) as log_configfile: logging.config.dictConfig( yaml.load(log_configfile.read(), Loader=yaml.SafeLoader) ) except Exception as e: logging.basicConfig(level=logging.DEBUG) logger.exception(e) if "SENTRY_DSN" in os.environ: make_sentry_logger() bot = SirBot() slack = SlackPlugin(**slack_configs) endpoints.slack.create_endpoints(slack) bot.load_plugin(slack) airtable = AirtablePlugin() endpoints.airtable.create_endpoints(airtable) bot.load_plugin(airtable) # Add route to respond to AWS health check bot.router.add_get("/health", handle_health_check) logging.getLogger("aiohttp.access").setLevel(logging.WARNING) bot.start(host=HOST, port=PORT, print=logger.info)
def create_endpoints(plugin: SlackPlugin): plugin.on_command('/here', slash_here, wait=False) plugin.on_command('/lunch', slash_lunch, wait=False) plugin.on_command('/repeat', slash_repeat, wait=False) plugin.on_command('/report', slash_report, wait=False)
async def test_start_no_bot_user_id(self, caplog): SlackPlugin(token='foo', verify='bar', bot_id='boo', admins=['aaa', 'bbb']) assert '`SLACK_BOT_USER_ID` not set' in caplog.text
async def test_start_find_bot_id(self, test_server, find_bot_id_query): bot = SirBot() bot.load_plugin(SlackPlugin(token='foo', verify='bar', bot_user_id='baz')) bot['plugins']['slack'].api.query = find_bot_id_query await test_server(bot) assert bot['plugins']['slack'].bot_id == 'B00000000'
async def bot(): b = SirBot() b.load_plugin(SlackPlugin(token='foo', verify='supersecuretoken', bot_user_id='baz', bot_id='boo', admins=['aaa', 'bbb'])) return b