-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# What this PR does This PR adds support for **/grafana escalate** command alongside with **/escalate.**
- Loading branch information
1 parent
f40634a
commit 805d442
Showing
5 changed files
with
156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from apps.slack.types.interaction_payloads import SlashCommandPayload | ||
|
||
|
||
class SlashCommand: | ||
""" | ||
SlashCommand represents slack slash command. | ||
Attributes: | ||
command -- command itself | ||
args -- list of args passed to command | ||
Examples: | ||
/grafana escalate | ||
SlashCommand(command='grafana', args=['escalate']) | ||
""" | ||
|
||
def __init__(self, command, args): | ||
# command itself | ||
self.command = command | ||
# list of args passed to command | ||
self.args = args | ||
|
||
@property | ||
def subcommand(self): | ||
""" | ||
Return first arg as subcommand | ||
""" | ||
return self.args[0] if len(self.args) > 0 else None | ||
|
||
@staticmethod | ||
def parse(payload: SlashCommandPayload): | ||
""" | ||
Parse slack slash command payload and return SlashCommand object | ||
""" | ||
command = payload["command"].lstrip("/") | ||
args = payload["text"].split() | ||
return SlashCommand(command, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from apps.slack.slash_command import SlashCommand | ||
|
||
|
||
def test_parse(): | ||
payload = { | ||
"command": "/grafana", | ||
"text": "escalate", | ||
"trigger_id": "trigger_id", | ||
"user_id": "user_id", | ||
"user_name": "user_name", | ||
"api_app_id": "api_app_id", | ||
} | ||
slash_command = SlashCommand.parse(payload) | ||
assert slash_command.command == "grafana" | ||
assert slash_command.args == ["escalate"] | ||
assert slash_command.subcommand == "escalate" | ||
|
||
|
||
def test_parse_command_without_subcommand(): | ||
payload = { | ||
"command": "/escalate", | ||
"text": "", | ||
"trigger_id": "trigger_id", | ||
"user_id": "user_id", | ||
"user_name": "user_name", | ||
"api_app_id": "api_app_id", | ||
} | ||
slash_command = SlashCommand.parse(payload) | ||
assert slash_command.command == "escalate" | ||
assert slash_command.args == [] | ||
assert slash_command.subcommand is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters