Skip to content

Send slack notifications from Salesforce Marketing Cloud

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
License.md
Notifications You must be signed in to change notification settings

MarketingThibs/slack-mc-notifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Send Slack Notifications From Marketing Cloud

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:

  1. Setup Slack's Incoming Webhooks
  2. Setup an AMPscript block
  3. Setup a script automation (if not using it from email or landing page)

Setup Slack's Incoming Webhooks

You can refere to Slack's Incoming Webhooks documentation. You will need to:

  1. Create a Slack app
  2. Enable Incoming Webhooks if you already have an app, you can edit your apps page directly
  3. Create an Incoming Webhook

slack-example-notif-1

💡 you can use one of the nice SLDS icons to make to app friendly with Einstein for instance

Setup an AMPscript block

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.

SIMPLE EXAMPLE

%%[
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.

EXAMPLE WITH ATTACHED IMAGE

%%[
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

Setup a script automation

  1. First save the AMPscript above into a content builder HTML block

  2. Create a Script Activity into the *Automation Studio

  3. 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>
  4. Create an Automation containing this script activity

About

Send slack notifications from Salesforce Marketing Cloud

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
License.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published