Github user tequalsme commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1774#discussion_r116322359
--- Diff:
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
---
@@ -102,6 +106,81 @@ public void testInvalidIconEmoji() {
}
@Test
+ public void testInvalidDynamicProperties() {
+ testRunner.setProperty(PutSlack.WEBHOOK_URL, server.getUrl());
+ testRunner.setProperty(PutSlack.WEBHOOK_TEXT, WEBHOOK_TEST_TEXT);
+ PropertyDescriptor dynamicProp = new PropertyDescriptor.Builder()
+ .dynamic(true)
+ .name("foo")
+ .build();
+ testRunner.setProperty(dynamicProp, "{\"a\": a}");
+
+ testRunner.enqueue("{}".getBytes());
+ testRunner.run(1);
+ testRunner.assertTransferCount(PutSlack.REL_FAILURE, 1);
+ }
+
+ @Test
+ public void testValidDynamicProperties() {
+ testRunner.setProperty(PutSlack.WEBHOOK_URL, server.getUrl());
+ testRunner.setProperty(PutSlack.WEBHOOK_TEXT, WEBHOOK_TEST_TEXT);
+ PropertyDescriptor dynamicProp = new PropertyDescriptor.Builder()
+ .dynamic(true)
+ .name("foo")
+ .build();
+ testRunner.setProperty(dynamicProp, "{\"a\": \"a\"}");
+
+ testRunner.enqueue("{}".getBytes());
+ testRunner.run(1);
+ testRunner.assertTransferCount(PutSlack.REL_FAILURE, 0);
+ }
+
+ @Test
+ public void testValidDynamicPropertiesWithExpressionLanguage() {
+ ProcessSession session =
testRunner.getProcessSessionFactory().createSession();
+ FlowFile ff = session.create();
+ Map<String, String> props = new HashMap<>();
+ props.put("foo", "\"bar\"");
+ props.put("ping", "pong");
+ ff = session.putAllAttributes(ff, props);
+
+ testRunner.setProperty(PutSlack.WEBHOOK_URL, server.getUrl());
+ testRunner.setProperty(PutSlack.WEBHOOK_TEXT, WEBHOOK_TEST_TEXT);
+ PropertyDescriptor dynamicProp = new PropertyDescriptor.Builder()
+ .dynamic(true)
+ .name("foo")
+ .build();
+ testRunner.setProperty(dynamicProp, "{\"foo\": ${foo},
\"ping\":\"${ping}\"}");
--- End diff --
The attachments can get pretty complex. For example, from the [Slack
docs](https://api.slack.com/docs/message-attachments):
```
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#36a64f",
"pretext": "Optional text that appears above the attachment
block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Optional text that appears within the attachment",
"fields": [
{
"title": "Priority",
"value": "High",
"short": false
}
],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon":
"https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
```
But more importantly, you could specify multiple attachment blocks like the
above, displayed in key-sorted order. So I am not sure how that would be
handled if the processor is building multiple JSON attachments from individual
key/value pairs. As the PR currently stands, the key is used for ordering of
attachments - thus the use of SortedSet.
FWIW, my team has been using this code for quite awhile now to create
"rich" Slack messages. Slack webhooks will return an error for malformed
attachments.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---