You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-28Lines changed: 83 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,67 +6,122 @@ This module has a single purpose: send messages to Slack channels.
6
6
7
7
Its features are
8
8
9
-
* uses Slack incoming Webhooks
10
-
*send messages to multiple channels in multiple workspaces
9
+
* uses Slack Incoming Webhooks
10
+
*Incoming Webhook URLs are stored encrypted
11
11
* create messages with markdown markup or just plain text
12
-
* specify message to be shown in the notification
13
-
* no Java, just native Mendix
12
+
* send messages to multiple channels in multiple workspaces
13
+
* message can be sent in the background not delaying your primary process
14
+
* no Java libraries that requires maintenance, just native Mendix
15
+
* Dutch and English languages are supported in the UI
14
16
15
17
## Installation
16
18
17
19
Download the module from the AppStore and add it to your project.
18
20
21
+
Add microflow `ASu_SlackMessage` to your app's AfterStartup microflow.
22
+
23
+
The module depends on AppStore module [CommunityCommons](https://appstore.home.mendix.com/link/app/170/).
24
+
25
+
## Constants
26
+
27
+
The module adds these constants to your app and adjust them when needed.
28
+
29
+
*`SlackMessage.AutoCreateIncomingWebhook` - Automatically create the requested webhook, marked invalid, to be completed later. Every used webhook should be defined and marked valid. But when an unknown webhook is used then it is added to be completed manually.
30
+
*`SlackMessage.SendEnabled` - By default messages are sent on test, acceptance and production systems. In case you want to disable sending messages on a specific system then set this constant to FALSE in the environment's configuration.
31
+
*`SlackMessage.SendEnabledInDev` - By default messages are not sent on development systems. This prevents messages being sent while developing an app. However when you want messages to be sent, change this constant value to TRUE in your project's profile.
32
+
*`SlackMessage.SlackRequestTimeout` - Slack web service request timeout in seconds.
33
+
34
+
This constant is added and you have to change it because the default value is unusable:
35
+
36
+
*`SlackMessage.EncryptionKey` - The encryption key used to encrypt sensitive data like the Incoming Webhook URL which does not need authentication. Its length should exactly be 16 characters (128 bit). By default this key is not set so you have to create your own secure key. It is advised to use a combination of uppercase and lowercase characters, digits and special characters.
37
+
38
+
This constant is added but you should not change it:
39
+
40
+
*`SlackMessage.EncryptionPrefix` - A string that indicates if a string is encrypted or not. Changing it might prevent you to upgrade in the future.
41
+
19
42
## Security
20
43
21
44
The module offers these two roles:
22
45
23
-
***Administrator** - manage Webhooks
24
-
***User** - the minimum needed for regular users
46
+
*`Administrator` - manage Webhooks
47
+
*`User` - the minimum needed for regular users
48
+
49
+
## Create Incoming Webhook(s) in Slack
50
+
51
+
First you have to create one or more Incoming Webhooks in Slack. You [can create an app](https://api.slack.com/messaging/webhooks) that adds the Webhook or add the [Incoming Webhook app](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks) to your Slack workspace and configure it. Which method you prefer is up to you, however Slack seems to prefer the first. In the end you need a Webhook URL to use the module. Such URL looks like `https://hooks.slack.com/services/somestring/anotherstring/alongerstring`.
25
52
26
-
## Create incoming Webhook(s)
53
+
## Store Incoming Webhook(s) in your app
27
54
28
-
First you have to create one or more incoming Webhooks in Slack. You [can create an app](https://api.slack.com/messaging/webhooks) that adds the Webhook or add the [Incoming Webhook app](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks) to your Slack workspace and configure it. Which method you prefer is up to you. In the end you need a Webhook URL to use the module. Such URL looks like `https://hooks.slack.com/services/somestring/anotherstring/alongerstring`.
55
+
The module offers two methods of storing and using Incoming Webhook URLs:
29
56
30
-
A Webhook has these properties (all are required):
57
+
1. create IncomingWebhook objects (provided by the module) where the URL is stored encrypted and in your microflows you refer to it using a unique key
58
+
2. store URLs using your own method and provide the clear text URL when sending messages
31
59
32
-
***Label** - a descriptive human readable label
33
-
***Key** - a sort unique key to be used in your microflows to find the right Webhook; only lowercase and uppercase characters, digits and underscores are allowed here
34
-
***URL** - the incoming Webhook URL
60
+
Which way is used to store the URLs in an app is not that important, pick what fits your app and requirements best. The convenience microflows described below support both.
35
61
36
-
Add snippet **SN_Webhook** to a page to manage your Webhooks. Additionally you can use microflow **Webhook_Ensure** in for example the AfterStartup flow to add the Webhooks to the database on app start.
62
+
### Store in entity IncomingWebhook
63
+
64
+
One way is to store URLs in entity `IncomingWebhook`. This allows the developer to store URLs **encrypted** and use multiple Incoming Webhooks in the app easily. The URLs are stored encrypted because they can be used without any means of authentication.
65
+
66
+
The entity has these attributes (all are required):
67
+
68
+
*`Label` - a descriptive human readable label
69
+
*`Key` - a sort unique key to be used in your microflows to find the right Webhook; only lowercase and uppercase characters, digits and underscores are allowed here
70
+
*`URL` - the Incoming Webhook URL
71
+
72
+
It is highly recommended to store the values for `Key` in an enumeration. This makes using them more consistent and prevents error by typos.
73
+
74
+
Add snippet `SN_Webhook` to a page to manage your Incoming Webhooks manually. Additionally you can use microflows `IncomingWebhook_Ensure` or `IncomingWebhook_Upsert` in for example the AfterStartup flow to add them to the database on app start automatically.
75
+
76
+
### Store using your own method
77
+
78
+
Another way is to store URLs using your own method and not use entity `IncomingWebhook` at all. For example the app uses just a single Incoming Webhook and its URL is stored in a constant. If encrypting the URL is less important then there is no need to create an `IncomingWebhook` object. The module provides microflows that can send messages to Slack based on a clear text URL.
37
79
38
80
## Create and send a single line message
39
81
40
-
Microflow **Message_CreateAndSend** can be used to send a single line message to Slack and can be used as an example how to use all steps separately with multi line messages.
82
+
The microflows `Message_CreateAndSendToWebhookKey` and `Message_CreateAndSendToWebhookURL` can be used to send a single line message to Slack and can be used as an example how to use all steps separately with multi line messages.
41
83
42
-
The microflow has these parameters:
84
+
The first microflow expects an `IncomingWebhook` object with the specified `key` to be in the database. The second microflow accepts an Incoming Webhook URL as input.
43
85
44
-
***NotificationText** - the text to be shown in the OS notification, max 200 characters
45
-
***NotificationTextType** - specify if the text markup is plain text or markdown
46
-
***MessageText** - the text with the "real" message, max 3000 characters; when *empty* then it is skipped and the notification text is used
47
-
***MessageTextType** - specify if the text markup is plain text or markdown
48
-
***WebhookKey** - the key of the Webhook to send the message to
86
+
The microflows have these parameters:
49
87
50
-
More details about, for example, text markup are in the paragraphs below.
88
+
*`NotificationText` - the text to be shown in the OS notification, max 200 characters
89
+
*`NotificationTextType` - specify if the text markup is plain text or markdown
90
+
*`MessageText` - the text with the "real" message, max 3000 characters; when *empty* then it is skipped and the notification text is used
91
+
*`MessageTextType` - specify if the text markup is plain text or markdown
92
+
*`IncomingWebhookKey` or `IncomingWebhookURL` - the key or full URL of the Incoming Webhook to send the message to
93
+
*`SendAsync` - use TRUE (preferred) to send the message in a separate background thread or FALSE to send it in the same thread
94
+
95
+
More details about text markup are in the paragraphs below.
96
+
97
+
On failure check the log file for details.
51
98
52
99
## Create and send a multi-line message
53
100
54
-
You start a multi-line message by creating the basis of a message using microflow **Message_Initialize**. It requires a string that contains the text to be shown in the notification created by Slack. So this is not the message in the channel, but an OS notification telling that there is a message. [Markdown](https://api.slack.com/reference/surfaces/formatting) can be used in this message.
101
+
You start a multi-line message by creating the basis of a message using microflow `Message_Initialize`. It requires a string that contains the text to be shown in the notification created by Slack. So this is not the message in the channel, but an OS notification telling that there is a message. [Markdown](https://api.slack.com/reference/surfaces/formatting) can be used in this message.
55
102
56
-
Next you add one or more lines to your message using microflow **Message_AddLine**. Also here [Markdown](https://api.slack.com/reference/surfaces/formatting) is supported.
103
+
Next you add one or more lines to your message using microflow `Message_AddLine`. Also here [Markdown](https://api.slack.com/reference/surfaces/formatting) is supported.
57
104
58
-
An example of the text in such a line is below. The resulting message starts with `@here` which notifies all active users. Next it shows a large blue dot (emoji) and a text where the word **UP** is in **bold**.
105
+
An example of the text in such a line is below. The resulting message starts with `@here` which notifies all active users. Next it shows a large blue dot (emoji) and a text where the word `UP` is in **bold**.
59
106
60
107
```auto
61
-
<!here> :large_blue_circle: all systems are *UP*
108
+
<!here> :green_heart: all systems are *UP*
62
109
```
63
110
64
-
An easy way to find the name of an emoji is to create a message in Slack manually and add the desired emoji. The popup where you search for your emoji shows the string to use.
111
+
An easy way to find the name of an emoji is to create a message in Slack manually, add the desired emoji and use the presented string. The popup where you search for your emoji shows the string to use.
65
112
66
-
When you have created the message you send it using microflow **Message_Send**. It requires the key of the Webhook that you created before.
113
+
When you have created the message then you send it using microflow `Message_SendToWebhookKey` or `Message_SendToWebhookURL`, depending which method to store Incoming Webhook URLs you decided to use. They have these parameters:
114
+
115
+
*`Message` - the `Message` object you created
116
+
*`IncomingWebhookKey` or `IncomingWebhookURL` - the key or full URL of the Incoming Webhook to send the message to
117
+
*`SendAsync` - use TRUE (preferred) to send the message in a separate background thread or FALSE to send it in the same thread
67
118
68
119
On failure check the log file for details.
69
120
70
121
## Test creating and sending messages
71
122
72
-
The GitHub repo contains a Mendix model that can be used to test the module before adding it to your project.
123
+
[The GitHub repo](https://github.com/ppoetsma/SlackMessage) contains a Mendix model with features that can be used to test the module before adding it to your project. Snippet `SN_Webhook` has test features as well.
124
+
125
+
## Feedback
126
+
127
+
Please leave your feedback in [the GitHub repo](https://github.com/ppoetsma/SlackMessage/issues).
0 commit comments