Add 'My Tasks' button #23

Merged
luketainton merged 1 commits from feature/mytasks into main 2023-04-20 20:37:01 +02:00
3 changed files with 42 additions and 4 deletions
Showing only changes of commit 1b8cb44e4b - Show all commits

View File

@ -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

View File

@ -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},
github-advanced-security[bot] commented 2023-04-20 20:36:38 +02:00 (Migrated from github.com)
Review

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

## Server certificates should be verified during SSL/TLS connections <!--SONAR_ISSUE_KEY:AYef9Chulpwl0QN40BfI-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=luketainton_roboluke-tasks&issues=AYef9Chulpwl0QN40BfI&open=AYef9Chulpwl0QN40BfI&pullRequest=23">SonarCloud</a></p> [Show more details](https://github.com/luketainton/roboluke-tasks/security/code-scanning/2)
)
return bool(resp.status_code == 200)

3
test.sh Executable file
View File

@ -0,0 +1,3 @@
export $(cat .env | xargs)
python -B -m app.main
unset BOT_NAME WEBEX_API_KEY ADMIN_FIRST_NAME ADMIN_EMAIL N8N_WEBHOOK_URL