You can use Slack Incoming Webhooks into a script automation, a landing page or email to send a notification to one of your Slack channel.
For example, setting reminders addressed to MC users or send a notification with a data extension records counts...
Steps:
- Setup Slack's Incoming Webhooks
- Setup an AMPscript block
- Setup a script automation (if not using it from email or landing page)
You can refere to Slack's Incoming Webhooks documentation. You will need to:
- Create a Slack app
- Enable Incoming Webhooks if you already have an app, you can edit your apps page directly
- Create an Incoming Webhook
💡 you can use one of the nice SLDS icons to make to app friendly with Einstein for instance
The AMPscript code block can be used in : an email, a landing page, then a script activity. In this example, we will use it into a script activity, but this would work with the other versions. We will use the TreatAsContent
and HTTPPost2
functions.
%%[
set @url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
/* "mrkdwn" parameter enables the slack markdown option */
set @contentLoad1 = '{"attachments": [{"title": "Msg title :smiley code:","mrkdwn": true,"text": "'
set @slackMsg = '*Bold Text*
- Some text here: %%=DataExtensionRowCount("MyDe")=%%
*OTHER BOLD TEXT*
- Some other text here: %%=DataExtensionRowCount("MyDe2")=%%'
/* "Color" of the attachment line*/
set @contentLoad2 = '","color": "#7CD197"}]}'
/* prepare the payload for the HTTPPOST */
set @contentLoad = TreatAsContent(concat(@contentLoad1,@slackMsg,@contentLoad2))
var @statusCode
var @response
/* Posts the message*/
set @post = HTTPPost2(@url,"application/json", @contentLoad, false,@statusCode, @response)
]%%
You can insert mpre personalisation thanks to AMPscript functions or add dyn images or formatted contents.
%%[
set @url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
set @contentLoad1 = '{"attachments": [{"title": "CONTACT DELETION REMINDER :warning:","mrkdwn": true,"text": "'
set @slackMsg = 'Reminder - Today we have *%%=DataExtensionRowCount("DeleteDE")=%%* extra contacts to delete !
1. Go to Contact Builder in All Contacts
2. Click on `delete` from data extension
3. Select the data extension from `Data Extensions > path > path`
4. Click On delete contacts'
set @contentLoad2 = '","color": "#d91e18", "image_url": "https://www.fillmurray.com/460/300"}]}'
set @contentLoad = TreatAsContent(concat(@contentLoad1,@slackMsg,@contentLoad2))
var @statusCode
var @response
set @post = HTTPPost2(@url,"application/json", @contentLoad, false,@statusCode, @response)
]%%
💡 Choose what you prefer and style your message thanks to Slack formating documentation and use the Message Builder to prepare your JSON
-
First save the AMPscript above into a content builder HTML block
-
Create a Script Activity into the *Automation Studio
-
Call the AMPscript block into your SSJS script
<script runat="server"> Platform.Load("Core", "1.1.1"); try { var ampscriptCode = Platform.Function.ContentBlockByID("ContentBlockByID"); var textBlock = TreatAsContent(ampscriptCode); } catch (ex) { Write("error message: " + ex); } </script>
-
Create an Automation containing this script activity