Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chat context to chatops #4609

Merged
merged 4 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contrib/chatops/actions/post_message.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ parameters:
type: "string"
description: "Channel to post to"
required: true
context:
type: "object"
description: "Context for channel (includes type of channel, user, etc.)"
required: false
extra:
type: "object"
description: "Extra adapter-specific parameters."
4 changes: 4 additions & 0 deletions contrib/chatops/actions/post_result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ parameters:
type: "string"
description: "Channel to post to"
required: true
context:
type: "object"
description: "Context for channel (includes type of channel, user, etc.)"
required: false
66 changes: 34 additions & 32 deletions contrib/chatops/actions/workflows/post_result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,43 @@ input:
- whisper
- execution_id
- channel
- context

tasks:
format_execution_result:
action: chatops.format_execution_result
input:
execution_id: "{{ ctx('execution_id') }}"
next:
-
when: "{{ result().result.enabled == true }}"
publish:
- message: "{{ result().result.message }}"
- extra: "{% if 'extra' in result().result %}{{ result().result.extra }}{% else %}{}{% endif %}"
do:
- post_message
-
when: "{{ result().result.enabled == false }}"
do:
- result_disabled
format_execution_result:
action: chatops.format_execution_result
input:
execution_id: "{{ ctx('execution_id') }}"
next:
-
when: "{{ result().result.enabled == true }}"
publish:
- message: "{{ result().result.message }}"
- extra: "{% if 'extra' in result().result %}{{ result().result.extra }}{% else %}{}{% endif %}"
do:
- post_message
-
when: "{{ result().result.enabled == false }}"
do:
- result_disabled

post_message:
action: chatops.post_message
input:
user: "{{ ctx('user') }}"
channel: "{{ ctx('channel') }}"
whisper: "{{ ctx('whisper') }}"
message: "{{ ctx('message') }}"
extra: "{{ ctx('extra') }}"
next:
- publish:
- msg: "Execution result has been posted."
post_message:
action: chatops.post_message
input:
user: "{{ ctx('user') }}"
channel: "{{ ctx('channel') }}"
whisper: "{{ ctx('whisper') }}"
message: "{{ ctx('message') }}"
context: "{{ ctx('context') }}"
extra: "{{ ctx('extra') }}"
next:
- publish:
- msg: "Execution result has been posted."

result_disabled:
action: core.noop
next:
- publish:
- msg: "Execution result is disabled."
result_disabled:
action: core.noop
next:
- publish:
- msg: "Execution result is disabled."
output:
- note: "{{ ctx('msg') }}"
1 change: 1 addition & 0 deletions contrib/chatops/rules/notify_hubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ action:
channel: "{{trigger.data.source_channel}}"
user: "{{trigger.data.user}}"
execution_id: "{{trigger.execution_id}}"
context: "{{trigger.data.source_context}}"
6 changes: 3 additions & 3 deletions st2api/st2api/controllers/v1/aliasexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def match_and_execute(self, input_api, requester_user, show_secrets=False):
'format': representation,
'command': command,
'user': input_api.user,
'source_channel': input_api.source_channel
'source_channel': input_api.source_channel,
}

# Add in any additional parameters provided by the user
Expand Down Expand Up @@ -145,7 +145,6 @@ def _post(self, payload, requester_user, show_secrets=False, match_multiple=Fals
'action_alias_ref': reference.get_ref_from_model(action_alias_db),
'api_user': payload.user,
'user': requester_user.name,
'source_channel': payload.source_channel
}

results = []
Expand Down Expand Up @@ -206,7 +205,8 @@ def _get_notify_field(self, payload):
on_complete.routes = [route]
on_complete.data = {
'user': payload.user,
'source_channel': payload.source_channel
'source_channel': payload.source_channel,
'source_context': getattr(payload, 'source_context', None),
}
notify = NotificationSchema()
notify.on_complete = on_complete
Expand Down
11 changes: 9 additions & 2 deletions st2common/st2common/models/api/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,17 @@ class AliasExecutionAPI(BaseAPI):
},
"source_channel": {
"type": "string",
"description": "Channel from which the execution was requested. This is not the \
channel as defined by the notification system.",
"description": "Channel from which the execution was requested. This is not the "
"channel as defined by the notification system.",
"required": True
},
"source_context": {
"type": "object",
"description": "ALL data included with the message (also called the message "
"envelope). This is currently only used by the Microsoft Teams "
"adapter.",
"required": False
},
"notification_channel": {
"type": "string",
"description": "StackStorm notification channel to use to respond.",
Expand Down