Luke Tainton
9830c5cc3a
* chore(pip-prod)(deps): bump pyparsing from 3.1.1 to 3.1.2 Bumps [pyparsing](https://github.com/pyparsing/pyparsing) from 3.1.1 to 3.1.2. - [Release notes](https://github.com/pyparsing/pyparsing/releases) - [Changelog](https://github.com/pyparsing/pyparsing/blob/master/CHANGES) - [Commits](https://github.com/pyparsing/pyparsing/compare/3.1.1...pyparsing_3.1.2) --- updated-dependencies: - dependency-name: pyparsing dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump packaging from 23.2 to 24.0 Bumps [packaging](https://github.com/pypa/packaging) from 23.2 to 24.0. - [Release notes](https://github.com/pypa/packaging/releases) - [Changelog](https://github.com/pypa/packaging/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pypa/packaging/compare/23.2...24.0) --- updated-dependencies: - dependency-name: packaging dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore(actions)(deps): bump mathieudutour/github-tag-action Bumps [mathieudutour/github-tag-action](https://github.com/mathieudutour/github-tag-action) from 6.1 to 6.2. - [Release notes](https://github.com/mathieudutour/github-tag-action/releases) - [Commits](https://github.com/mathieudutour/github-tag-action/compare/v6.1...v6.2) --- updated-dependencies: - dependency-name: mathieudutour/github-tag-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump autopep8 from 2.0.4 to 2.1.0 Bumps [autopep8](https://github.com/hhatto/autopep8) from 2.0.4 to 2.1.0. - [Release notes](https://github.com/hhatto/autopep8/releases) - [Commits](https://github.com/hhatto/autopep8/compare/v2.0.4...v2.1.0) --- updated-dependencies: - dependency-name: autopep8 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump filelock from 3.13.1 to 3.13.2 Bumps [filelock](https://github.com/tox-dev/py-filelock) from 3.13.1 to 3.13.2. - [Release notes](https://github.com/tox-dev/py-filelock/releases) - [Changelog](https://github.com/tox-dev/filelock/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/py-filelock/compare/3.13.1...3.13.2) --- updated-dependencies: - dependency-name: filelock dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump filelock from 3.13.2 to 3.13.3 Bumps [filelock](https://github.com/tox-dev/py-filelock) from 3.13.2 to 3.13.3. - [Release notes](https://github.com/tox-dev/py-filelock/releases) - [Changelog](https://github.com/tox-dev/filelock/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/py-filelock/compare/3.13.2...3.13.3) --- updated-dependencies: - dependency-name: filelock dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump filelock from 3.13.3 to 3.13.4 Bumps [filelock](https://github.com/tox-dev/py-filelock) from 3.13.3 to 3.13.4. - [Release notes](https://github.com/tox-dev/py-filelock/releases) - [Changelog](https://github.com/tox-dev/filelock/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/py-filelock/compare/3.13.3...3.13.4) --- updated-dependencies: - dependency-name: filelock dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump idna from 3.6 to 3.7 Bumps [idna](https://github.com/kjd/idna) from 3.6 to 3.7. - [Release notes](https://github.com/kjd/idna/releases) - [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst) - [Commits](https://github.com/kjd/idna/compare/v3.6...v3.7) --- updated-dependencies: - dependency-name: idna dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(pip-prod)(deps): bump virtualenv from 20.25.1 to 20.25.3 Bumps [virtualenv](https://github.com/pypa/virtualenv) from 20.25.1 to 20.25.3. - [Release notes](https://github.com/pypa/virtualenv/releases) - [Changelog](https://github.com/pypa/virtualenv/blob/main/docs/changelog.rst) - [Commits](https://github.com/pypa/virtualenv/compare/20.25.1...20.25.3) --- updated-dependencies: - dependency-name: virtualenv dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Add APM (#184) * Add APM * Fix unit tests * Remove apm.py * Add SonarCloud recommendations * SonarCloud python:S6890 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
174 lines
6.0 KiB
Python
174 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import logging
|
|
import sentry_sdk
|
|
|
|
from webex_bot.models.command import Command
|
|
from webex_bot.models.response import Response, response_from_adaptive_card
|
|
from webexteamssdk.models.cards import (
|
|
AdaptiveCard,
|
|
Column,
|
|
ColumnSet,
|
|
Date,
|
|
FontSize,
|
|
FontWeight,
|
|
Text,
|
|
TextBlock,
|
|
)
|
|
from webexteamssdk.models.cards.actions import Submit
|
|
|
|
from app.utils.config import config
|
|
from app.utils.n8n import get_tasks, submit_task
|
|
|
|
log: logging.Logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SubmitTaskCommand(Command):
|
|
def __init__(self) -> None:
|
|
super().__init__(
|
|
command_keyword="submit_feedback_dstgmyn",
|
|
help_message="Submit Task",
|
|
chained_commands=[SubmitTaskCallback(), MyTasksCallback()],
|
|
delete_previous_message=True,
|
|
)
|
|
self.sender: str = ""
|
|
|
|
def pre_execute(self, message, attachment_actions, activity) -> None:
|
|
self.sender = activity.get("actor").get("id")
|
|
|
|
def execute(self, message, attachment_actions, activity) -> Response:
|
|
card_body: list = [
|
|
ColumnSet(
|
|
columns=[
|
|
Column(
|
|
items=[
|
|
TextBlock(
|
|
"Submit Task",
|
|
weight=FontWeight.BOLDER,
|
|
size=FontSize.MEDIUM,
|
|
),
|
|
TextBlock(
|
|
f"Add a task to {config.admin_first_name}'s To Do list. All fields are required. Please don't use special characters.",
|
|
wrap=True,
|
|
isSubtle=True,
|
|
),
|
|
],
|
|
width=2,
|
|
)
|
|
]
|
|
),
|
|
ColumnSet(
|
|
columns=[
|
|
Column(
|
|
width=2,
|
|
items=[
|
|
Text(id="issue_title", placeholder="Summary", maxLength=100),
|
|
Text(
|
|
id="issue_description",
|
|
placeholder="Description",
|
|
maxLength=1000,
|
|
isMultiline=True,
|
|
),
|
|
Date(id="completion_date", placeholder="Completion Date"),
|
|
],
|
|
),
|
|
]
|
|
),
|
|
]
|
|
|
|
if self.sender in config.admin_emails:
|
|
card_body.append(
|
|
ColumnSet(
|
|
columns=[
|
|
Column(
|
|
width=1,
|
|
items=[
|
|
Text(
|
|
id="issue_requester",
|
|
placeholder="Requester Email (leave blank to submit for yourself)",
|
|
maxLength=100,
|
|
),
|
|
],
|
|
),
|
|
]
|
|
),
|
|
)
|
|
|
|
card: AdaptiveCard = AdaptiveCard(
|
|
body=card_body,
|
|
actions=[
|
|
Submit(
|
|
title="Submit",
|
|
data={
|
|
"callback_keyword": "submit_task_callback_rbamzfyx",
|
|
"sender": self.sender,
|
|
},
|
|
),
|
|
Submit(
|
|
title="My Submitted Tasks",
|
|
data={
|
|
"callback_keyword": "my_tasks_callback_rbamzfyx",
|
|
"sender": self.sender,
|
|
},
|
|
),
|
|
Submit(title="Cancel", data={"command_keyword": "exit"}),
|
|
],
|
|
)
|
|
with sentry_sdk.start_transaction(name="submit_task_command"):
|
|
return response_from_adaptive_card(card)
|
|
|
|
|
|
class SubmitTaskCallback(Command):
|
|
def __init__(self) -> None:
|
|
super().__init__(
|
|
card_callback_keyword="submit_task_callback_rbamzfyx", delete_previous_message=True
|
|
)
|
|
self.msg: str = ""
|
|
|
|
def pre_execute(self, message, attachment_actions, activity) -> None:
|
|
issue_title: str = attachment_actions.inputs.get("issue_title")
|
|
issue_description: str = attachment_actions.inputs.get("issue_description")
|
|
completion_date: str = attachment_actions.inputs.get("completion_date")
|
|
|
|
sender: str = attachment_actions.inputs.get("sender")
|
|
issue_requester: str = attachment_actions.inputs.get("issue_requester") or sender
|
|
|
|
if not issue_title or not issue_description or not completion_date:
|
|
self.msg = "Please complete all fields."
|
|
return
|
|
|
|
result: bool = submit_task(
|
|
requestor=issue_requester,
|
|
summary=issue_title,
|
|
description=issue_description,
|
|
completion_date=completion_date,
|
|
)
|
|
|
|
self.msg = (
|
|
"Submitting your task..." if result else "Failed to submit task. Please try again."
|
|
)
|
|
|
|
def execute(self, message, attachment_actions, activity) -> str:
|
|
with sentry_sdk.start_transaction(name="submit_task_callback"):
|
|
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:
|
|
with sentry_sdk.start_transaction(name="my_tasks_preexec"):
|
|
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)
|
|
with sentry_sdk.start_transaction(name="my_tasks_exec"):
|
|
if not result:
|
|
return "Failed to get tasks. Please try again."
|
|
return
|