def resolve(base_url, content, slack_client, request): """Resolves which create functionality (text/dialog) to invoke. Arguments: base_url (string): The base a Jama URL content (JSON Object): Payload from dialog submission slack_client (SlackClient Object): to invoke slack dialog request (Request Object): Request object to pass down Returns: Response (object): To make the response, we use make_response() from the flask library. Raises: AssertionError: This type of exception happens when trying to gather data from the Jama API to return to the Slack dialog API call. Exception: On any error with parsing user data, we throw a general exception and return make_response() with either 400 or 500 """ team_id = request.form["team_id"] user_id = request.form["user_id"] if isinstance(content, int): # Makes sure content is an int # content is the projectID try: # opens dialog, passed projectId as content slack_client.api_call("dialog.open", trigger_id=request.form["trigger_id"], dialog=create_fields(content, team_id, user_id)) except AssertionError as err: print(err) return commands_info.create( request, headline="Oh no, there was an issue locating your project") except Exception as err: # Returns error message to user & 400 status print(err) return user_error(request) else: try: content_dict = make_dict(content) item_create_response = create.from_text(base_url, content_dict, team_id, user_id) tools.return_to_slack(request, item_create_response) except Exception as err: print(err) return commands_info.create( request, headline="Oh no, we had trouble handling your data!" ) # Server/parse error return make_response("", 200)
def resolve(base_url, content, slack_client, request): """Resolves which create functionality (text/dialog) to invoke. Args: base_url (string): The base a Jama URL content (JSON Object): Payload from dialog submission slack_client (SlackClient Object): to invoke slack dialog request (Request Object): Request object to pass down Returns: Response (object): To make the response, we use make_response() from the flask library. Raises: AssertionError: This type of exception happens when trying to gather data from the Jama API to return to the Slack dialog API call. Exception: On any error with parsing user data, we throw a general exception and return make_response() with either 400 or 500 """ global user_project_id_list try: slack_team_id = request.form["team_id"] slack_user_id = request.form["user_id"] if content == "": if (slack_team_id, slack_user_id) in user_project_id_list: del user_project_id_list[(slack_team_id, slack_user_id)] slack_client.api_call("dialog.open", trigger_id=request.form["trigger_id"], dialog=dialog.comment_dialog()) else: args = make_dict(content) if "id" not in args or "comment" not in args: return commands_info.comment( request, "Oh no, there was an error with your inputs!") comment_create_response = comment.from_inline( slack_team_id, slack_user_id, base_url, args) tools.return_to_slack(request, comment_create_response) return make_response("", 200) except AssertionError: return api_error(request, "comment") except Exception as err: print(err) return commands_info.comment( request, "Oh no, there was an error with your inputs!" ) # Server/parse error
def resolve_display_req(base_url, content): """ @params: base_url -> url to pass down content -> contains search key (i.e. "id=jama item ID") """ try: # Make dictionary of the key value pairs encoded in content content = make_dict(content) # Assigns JSON obj to search result search_result = search.search_by_id(base_url, content["id"]) tools.return_to_slack(request, search_result) return make_response("", 200) except Exception as e: print(e) return commands_info.search(request, headline="There was an error with your command! Here is a quick guide to using `/jamaconnect display`:")
def resolve_oauth_req(req, content): """ @params: req -> Request to process content -> Arguments from Slack user """ try: if content == "": slack_client.api_call("dialog.open", trigger_id=request.form["trigger_id"], dialog=oauth_dialog_json.oauth_dialog()) return make_response("", 200) content = make_dict(content) return oauth.add_credentials(request.form["team_id"], request.form["user_id"], content["id"], content["secret"]) except Exception as e: print(e) return make_response("Invalid input! Usage: /jamaconnect oauth: id=[your client ID], secret=[your client secret] (or just \"/jamaconnect oauth\" for an interactive dialog)", 200)