Add 'My Tasks' button #23
| @@ -17,7 +17,7 @@ from webexteamssdk.models.cards import ( | |||||||
| from webexteamssdk.models.cards.actions import Submit | from webexteamssdk.models.cards.actions import Submit | ||||||
|  |  | ||||||
| from app.utils.config import config | from app.utils.config import config | ||||||
| from app.utils.n8n import submit_task | from app.utils.n8n import submit_task, get_tasks | ||||||
|  |  | ||||||
| log: logging.Logger = logging.getLogger(__name__) | log: logging.Logger = logging.getLogger(__name__) | ||||||
|  |  | ||||||
| @@ -27,7 +27,7 @@ class SubmitTaskCommand(Command): | |||||||
|         super().__init__( |         super().__init__( | ||||||
|             command_keyword="submit_feedback_dstgmyn", |             command_keyword="submit_feedback_dstgmyn", | ||||||
|             help_message="Submit Task", |             help_message="Submit Task", | ||||||
|             chained_commands=[SubmitTaskCallback()], |             chained_commands=[SubmitTaskCallback(), MyTasksCallback()], | ||||||
|             delete_previous_message=True, |             delete_previous_message=True, | ||||||
|         ) |         ) | ||||||
|         self.sender: str = "" |         self.sender: str = "" | ||||||
| @@ -36,7 +36,6 @@ class SubmitTaskCommand(Command): | |||||||
|         self.sender = activity.get("actor").get("id") |         self.sender = activity.get("actor").get("id") | ||||||
|  |  | ||||||
|     def execute(self, message, attachment_actions, activity) -> Response: |     def execute(self, message, attachment_actions, activity) -> Response: | ||||||
|  |  | ||||||
|         card_body: list = [ |         card_body: list = [ | ||||||
|             ColumnSet( |             ColumnSet( | ||||||
|                 columns=[ |                 columns=[ | ||||||
| @@ -104,6 +103,13 @@ class SubmitTaskCommand(Command): | |||||||
|                         "sender": self.sender, |                         "sender": self.sender, | ||||||
|                     }, |                     }, | ||||||
|                 ), |                 ), | ||||||
|  |                 Submit( | ||||||
|  |                     title="My Tasks", | ||||||
|  |                     data={ | ||||||
|  |                         "callback_keyword": "my_tasks_callback_rbamzfyx", | ||||||
|  |                         "sender": self.sender, | ||||||
|  |                     }, | ||||||
|  |                 ), | ||||||
|                 Submit(title="Cancel", data={"command_keyword": "exit"}), |                 Submit(title="Cancel", data={"command_keyword": "exit"}), | ||||||
|             ], |             ], | ||||||
|         ) |         ) | ||||||
| @@ -142,3 +148,21 @@ class SubmitTaskCallback(Command): | |||||||
|  |  | ||||||
|     def execute(self, message, attachment_actions, activity) -> str: |     def execute(self, message, attachment_actions, activity) -> str: | ||||||
|         return self.msg |         return self.msg | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class MyTasksCallback(Command): | ||||||
|  |     def __init__(self) -> None: | ||||||
|  |         super().__init__( | ||||||
|  |             card_callback_keyword="my_tasks_callback_rbamzfyx", delete_previous_message=True | ||||||
|  |         ) | ||||||
|  |         self.msg: str = "" | ||||||
|  |  | ||||||
|  |     def pre_execute(self, message, attachment_actions, activity) -> str: | ||||||
|  |         return "Getting your tasks..." | ||||||
|  |  | ||||||
|  |     def execute(self, message, attachment_actions, activity) -> str | None: | ||||||
|  |         sender: str = attachment_actions.inputs.get("sender") | ||||||
|  |         result: bool = get_tasks(requestor=sender) | ||||||
|  |         if not result: | ||||||
|  |             return "Failed to get tasks. Please try again." | ||||||
|  |         return | ||||||
|   | |||||||
| @@ -16,7 +16,6 @@ def __n8n_post(data: dict) -> bool: | |||||||
|  |  | ||||||
|  |  | ||||||
| def submit_task(summary, description, completion_date, requestor) -> bool: | def submit_task(summary, description, completion_date, requestor) -> bool: | ||||||
|     print(f"submit_task: {completion_date=}") |  | ||||||
|     data: dict = { |     data: dict = { | ||||||
|         "requestor": requestor, |         "requestor": requestor, | ||||||
|         "title": summary, |         "title": summary, | ||||||
| @@ -24,3 +23,15 @@ def submit_task(summary, description, completion_date, requestor) -> bool: | |||||||
|         "completiondate": completion_date, |         "completiondate": completion_date, | ||||||
|     } |     } | ||||||
|     return __n8n_post(data=data) |     return __n8n_post(data=data) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def get_tasks(requestor) -> bool: | ||||||
|  |     headers: dict = {"Content-Type": "application/json"} | ||||||
|  |     resp: requests.Response = requests.get( | ||||||
|  |         url=config.n8n_webhook_url, | ||||||
|  |         headers=headers, | ||||||
|  |         timeout=10, | ||||||
|  |         verify=False, | ||||||
|  |         params={"requestor": requestor}, | ||||||
|  | |||||||
|  |     ) | ||||||
|  |     return bool(resp.status_code == 200) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	
Server certificates should be verified during SSL/TLS connections
Enable server certificate validation on this SSL/TLS connection.See more on SonarCloud
Show more details