-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
chatops.post_message seems to be ignoring Slack pretext #162
Comments
Is the rest of the Slack message appearing? With the correct color, title, title link, author, author link, author icon, image, and fields? |
Yes, certainly is (sorry, should have mentioned that). |
Any thoughts here? Anything I can do to help? |
I don't think your usage of the TL;DR: I think you are interpreting Slack's API incorrectly. In the linked st2 issue, the following {
"color": "#474C5D",
"mattermost": {
"attachments": [
{
"pretext": "---",
"actions": [
{
"integration": {
"url": "https://example.com",
"context": {
"some": "value"
}
},
"name": "button name"
}
],
"text": "example"
}
]
}
} Note the This is the JSON that you are sending in the {
"slack": {
"color": "#f48527",
"pretext": "Hey <!channel>, Ready for ChatOps?",
"title": "Ansible and ChatOps. Get started :rocket:",
"title_link": "https://stackstorm.com/2015/06/24/ansible-chatops-get-started-%f0%9f%9a%80/",
"author_name": "by StackStorm - IFTTT for Ops",
"author_link": "https://stackstorm.com/",
"author_icon": "https://stackstorm.com/wp/wp-content/uploads/2015/01/favicon.png",
"image_url": "https://i.imgur.com/HWN8T78.png",
"fields": [
{
"title": "Documentation",
"value": "https://docs.stackstorm.com/chatops/",
"short": true
}
]
}
} See how it's missing the Perusing Slack's messy yet useful documentation, I have not found that In fact, using Slack's own message formatter, I have found that the way you are trying to use
Using that same formatter, I have verified that So please try using this data instead: {
"color": "#474C5D",
"slack": {
"attachments": [
{
"color": "#f48527",
"pretext": "Hey <!channel>, Ready for ChatOps?",
"title": "Ansible and ChatOps. Get started :rocket:",
"title_link": "https://stackstorm.com/2015/06/24/ansible-chatops-get-started-%f0%9f%9a%80/",
"author_name": "by StackStorm - IFTTT for Ops",
"author_link": "https://stackstorm.com/",
"author_icon": "https://stackstorm.com/wp/wp-content/uploads/2015/01/favicon.png",
"image_url": "https://i.imgur.com/HWN8T78.png",
"fields": [
{
"title": "Documentation",
"value": "https://docs.stackstorm.com/chatops/",
"short": true
}
]
}
]
}
} |
@blag Requiring
You can see in the example that I assume the Mattermost adapter code handles things differently which is why What is the correct way Slack extra paramters should be handled? I know you've been working on updating hubot components, has there been changes in the slack adapter that mean the st2 documentation is no longer correct? |
Yeah, basically what @nzlosh said. The CLI example I originally pasted is actually from an example somewhere in the st2 repos, but that said, the doco does indicate that using: "slack_extra": {
"slack": { Uses attachments in the "backend" when sent to Slack. An example of my trigger instance (which clearly shows up as a card/attachment in Slack): "slack_extra": {
"slack": {
"title": "xxx",
"color": "danger",
"text": "An alert",
"author_name": "ServiceNow",
"title_link": "https://xxx",
"mrkdwn_in": [
"fields"
],
"fields": [
{
"short": true,
"value": "xxx",
"title": "CI"
},
{
"short": true,
"value": "2 - High",
"title": "Priority"
},
{
"short": true,
"value": "01-Mar-2019 00:17:29",
"title": "First notified"
},
{
"short": true,
"value": "Active",
"title": "External status"
},
{
"short": false,
"value": "yyy",
"title": "Last update"
}
],
"pretext": "Something",
"fallback": "xxx",
"author_icon": "https://zzz"
}
} |
Hi @blag, any further thoughts here? |
@lingfish Can you find where the docs stated to use Regarding how to us attachments with Mattermost, using
Can you see what data is being sent to the Mattermost server? Adding end-to-end tests to ChatOps with Mattermost is on my list of things to do after 3.0 is released. |
Ok, so a few confusing things going on here, including from me ;) Firstly, I'm using Slack, not Mattermost. Secondly, the payload being sent is actually this:
Not what I pasted above; there is no
My sensor sends that extra data using In the doco, it states:
This implies that anything supplied in Inserting the above JSON, from
|
Sorry for the confusion regarding Mattermost vs. Slack! UnfortunatelyI think you have found a bug in our documentation. This statement from our documentation:
is not 100% true. The dictionary that is passed to the Slack Attachment API is NOT passed as-is, it is completely mangled by the hubot-stackstorm Slack adapter. But there is still hope!There are two paths in the Slack adapter for handling Originally, sending custom attachments was not supported in the adapter (see here). I added the ability to specify your own attachments in 14275e9626021d28a1657acf823de5deec3e6742. However, I needed to preserve backwards compatibility, so there are now two code paths for sending Slack messages with attachments:
But the second (original) code path unconditionally mangled the pretext: content.pretext = i === 0 ? pretext + split_message.pretext : null;
content.text = chunks[i];
content.fallback = chunks[i];
robot.adapter.client.send(envelope, {'attachments': [content]}); Really, a better description of what it does is it completely ignores any pretext that is set by you, the user. Furthermore, if you look through the first code path, you'll notice that it is comparatively incredibly simple: var messages_to_send = messages.buildMessages(data.extra.slack);
var sendMessage = function (i) {
robot.adapter.client.send(envelope, messages_to_send[i]);
if (messages_to_send.length > ++i) {
setTimeout(function(){sendMessage(i);}, 300);
}
};
sendMessage(0); The first code path does not mangle the What this means for youPlease fully specify the attachments you wish to send, so the code takes the first (safer) code path: ---
name: "notify_slack"
pack: "xx_st2"
description: "Send to Slack."
enabled: true
trigger:
type: "xx_st2.evt_trigger"
parameters: {}
action:
ref: "chatops.post_message"
parameters:
message: "{{trigger.message}}"
channel: "testing"
extra:
slack:
attachments: "{{ trigger.slack_extra_attachments }}" # Should be an array, see the Slack Attachments API The value of the I cannot really properly "fix" this bug, because doing so would create issues for other users who do expect Other considerationsAdditional
|
Love it, thanks @blag! That was the most epic and awesome dev issue comment I've read :) Pity about the constraints though. I'll try your suggestion soon. Meanwhile, Slack are at it again, improving etc. Now they have a thing called blocks. Perhaps if/when this project moves to it, that non-breaking change can be implemented. |
Hi again @blag ... So, I've tried it as suggested and hit a bit of a wall. It seems that no jinja parsing is done, if done as above?
It seems to have just I've tried variants using Thoughts? |
Pinging @blag 😉 |
@lingfish Can you post your entire alias (feel free to redact/change any sensitive information)? It's difficult to troubleshoot when I don't know what you've written. |
Do you mean my rule? There is no alias. If rule, here it is:
|
I'm having a hard time reconstructing what you are doing. Can you post a snapshot of everything you have right now? Attempting to reconstruct what's going on... "extra": {
"slack": {
"attachments": "[{u'title': u'something', u'color': u'#a0a0a0', u'text': u'something', ... ]"
}
} ^ This appears to be the data that is being passed into So if this is your rule YAML (copied/pasted from above): ---
name: "notify_slack"
pack: "xxx_st2"
description: "Send to Slack."
enabled: true
trigger:
type: "xxx_st2.evt_trigger"
parameters: {}
action:
ref: "chatops.post_message"
parameters:
message: "{{trigger.message}}"
channel: "testing"
extra:
slack:
attachments: "{{ trigger.slack_extra }}" It would stand to reason that your trigger data is: "slack_extra": [
{
"title": "something",
"color": "#a0a0a0",
"text": "something",
...
}
] Which doesn't look right. I would double check what your trigger instance data is. Make sure it is an object/dictionary and not a string. Once you've verified it, please post it here verbatim so I can follow along. Once you have verified the trigger instance data is what you expect it to be, you can also try to use the ---
name: "notify_slack"
pack: "xxx_st2"
description: "Send to Slack."
enabled: true
trigger:
type: "xxx_st2.evt_trigger"
parameters: {}
action:
ref: "chatops.post_message"
parameters:
message: "{{trigger.message}}"
channel: "testing"
extra:
slack:
attachments: "{{ trigger.slack_extra | from_json_string }}" |
Sorry, you're right, more data needed from me. Ok, so... the rule above is right. Heavily redacted below, but done carefully to not lose quotes etc. Yes, that's the data that is being passed into {
"extra": {
"slack": {
"attachments": "[{u'title': u'zzz', u'color': u'danger', u'text': u'NOTIFICATION', u'author_name': u'zzz', u'title_link': u'zzz', u'mrkdwn_in': [u'fields'], u'fields': [{u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'Active', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'1', u'title': u'zzz'}, {u'short': False, u'value': u'zzz', u'title': u'zzz'}], u'pretext': u'', u'fallback': u'zzz', u'author_icon': u'zzz'}]"
}
},
"whisper": false,
"user": null,
"output": {
"whisper": false,
"message": "NOTIFICATION",
"user": null,
"channel": "testing",
"extra": {
"slack": {
"attachments": "[{u'title': u'zzz', u'color': u'danger', u'text': u'NOTIFICATION', u'author_name': u'zzz', u'title_link': u'zzz', u'mrkdwn_in': [u'fields'], u'fields': [{u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'zzz', u'title': u'zzz'}, {u'short': True, u'value': u'1', u'title': u'zzz'}, {u'short': False, u'value': u'zzz', u'title': u'zzz'}], u'pretext': u'', u'fallback': u'zzz', u'author_icon': u'zzz'}]"
}
}
},
"message": "NOTIFICATION",
"channel": "testing"
} Here is the trigger instance: {
"status": "processed",
"occurrence_time": "2019-05-09T13:16:03.000000Z",
"trigger": "pack.trigger",
"id": "5cd39b73e8a12c310f1e5ddc",
"payload": {
"param": "zzz",
"param": false,
"param": 1,
"param": "zzz",
"param": "zzz",
"param": "zzz",
"param": "zzz",
"param": "zzz",
"slack_extra": [
{
"title": "zzz",
"color": "danger",
"text": "NOTIFICATION",
"author_name": "zzz",
"title_link": "zzz",
"mrkdwn_in": [
"fields"
],
"fields": [
{
"short": true,
"value": "zzz",
"title": "zzz"
},
{
"short": true,
"value": "zzz",
"title": "zzz"
},
{
"short": true,
"value": "zzz",
"title": "zzz"
},
{
"short": true,
"value": "zzz",
"title": "zzz"
},
{
"short": true,
"value": "zzz",
"title": "zzz"
},
{
"short": true,
"value": "1",
"title": "zzz"
},
{
"short": false,
"value": "zzz",
"title": "zzz"
}
],
"pretext": "",
"fallback": "zzz",
"author_icon": "zzz"
}
],
"short_description": "zzz",
"message": "zzz",
"cmdb_ci": {
"link": "zzz",
"display_value": "zzz"
}
}
} So the trigger instance data looks like an object to me... but as stated above, the The snippet of my Python code for the sensor: payload['slack_extra'] = [
{
'fallback': 'zzz {}: {}'.format(record['zzz'], record['yyy']),
'author_name': 'zzz',
'author_icon': 'zzz',
'title': record['zzz'],
... Finally, I had already tried {
"traceback": " File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/enforcer.py\", line 200, in _invoke_action\n additional_contexts=additional_contexts)\n File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/enforcer.py\", line 82, in get_resolved_parameters\n additional_contexts=additional_contexts)\n File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/param.py\", line 297, in render_live_params\n context = _resolve_dependencies(G)\n File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/param.py\", line 215, in _resolve_dependencies\n raise ParamException(msg)\n",
"error": "Failed to render parameter \"extra\": Expecting property name enclosed in double quotes: line 1 column 3 (char 2)"
} |
Can you post the YAML metadata file for your sensor? |
Sure, for this though you'll need non-redacted fields, right? If so, can I mail it or similar, commercially-sensitive stuff in there. |
You are welcome to either redact field values (use your best judgment on that) and post it here or you can DM me via our Slack community (I'm also blag on that). |
Alright, so upon trying to modify the sensor schema, I get an error for
When specifying array, it just goes through again as a string :( |
Also just for fun, from the sensor I've send an object |
Okay, so since the data being passed to The issue is farther back in the trigger chain - in the rule itself. Because of that, this bug is in the st2 project itself and the original issue StackStorm/st2#4561 is the proper place to handle this. @lingfish Is that acceptable to you? Sorry to push you back over to that issue, but it looks like there's nothing to do/fix in this project. I'll keep this open for a week or until you respond, whichever comes first. Then I'll close it and post the information we've figured out here back into the original st2 issue. |
Originally logged here: StackStorm/st2#4561, @nzlosh suggested I might re-log it here.
SUMMARY
chatops.post_message
seems to be ignoring Slackpretext
.ISSUE TYPE
Pick one below and delete the rest:
STACKSTORM VERSION
st2 2.10.1, on Python 2.7.6
OS / ENVIRONMENT / INSTALL METHOD
Standard docker install.
STEPS TO REPRODUCE
EXPECTED RESULTS
A pretext line in the Slack channel.
ACTUAL RESULTS
Pretext line missing.
The text was updated successfully, but these errors were encountered: