Add 'My Tasks' button (#23)
This commit is contained in:
parent
d8aee6341b
commit
8eafc402ac
@ -17,7 +17,7 @@ from webexteamssdk.models.cards import (
|
||||
from webexteamssdk.models.cards.actions import Submit
|
||||
|
||||
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__)
|
||||
|
||||
@ -27,7 +27,7 @@ class SubmitTaskCommand(Command):
|
||||
super().__init__(
|
||||
command_keyword="submit_feedback_dstgmyn",
|
||||
help_message="Submit Task",
|
||||
chained_commands=[SubmitTaskCallback()],
|
||||
chained_commands=[SubmitTaskCallback(), MyTasksCallback()],
|
||||
delete_previous_message=True,
|
||||
)
|
||||
self.sender: str = ""
|
||||
@ -36,7 +36,6 @@ class SubmitTaskCommand(Command):
|
||||
self.sender = activity.get("actor").get("id")
|
||||
|
||||
def execute(self, message, attachment_actions, activity) -> Response:
|
||||
|
||||
card_body: list = [
|
||||
ColumnSet(
|
||||
columns=[
|
||||
@ -104,6 +103,13 @@ class SubmitTaskCommand(Command):
|
||||
"sender": self.sender,
|
||||
},
|
||||
),
|
||||
Submit(
|
||||
title="My Tasks",
|
||||
data={
|
||||
"callback_keyword": "my_tasks_callback_rbamzfyx",
|
||||
"sender": self.sender,
|
||||
},
|
||||
),
|
||||
Submit(title="Cancel", data={"command_keyword": "exit"}),
|
||||
],
|
||||
)
|
||||
@ -142,3 +148,21 @@ class SubmitTaskCallback(Command):
|
||||
|
||||
def execute(self, message, attachment_actions, activity) -> str:
|
||||
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:
|
||||
print(f"submit_task: {completion_date=}")
|
||||
data: dict = {
|
||||
"requestor": requestor,
|
||||
"title": summary,
|
||||
@ -24,3 +23,15 @@ def submit_task(summary, description, completion_date, requestor) -> bool:
|
||||
"completiondate": completion_date,
|
||||
}
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user