Adding a Mailchimp subscriber when a new message is added to Slack

Learn how easy it is to create an event-driven flow that is triggered by a new message in Slack so that you can perform an action in another app.

Note: This tutorial assumes that you have signed up for free or trial accounts for Slack and MailChimp, or that you have business accounts.
Figure 1. Watch the video

Time required:

If you have already connected Slack and MailChimp to App Connect, the steps to create and test the integration flow in this tutorial should take only a few minutes.

Scenario:

You're running a successful start-up that hosts popular coding events. Everybody wants to be added as subscribers to your mailing list so that they can be informed when the latest event is running. You're being bombarded with requests and can't cope because you never have time to add individuals to your mailing list in MailChimp. You wish they could add themselves to the mailing list! It sounds ridiculous; however, this is possible with App Connect. By using Slack's New Message action you can create a new flow so that every time a potential attendee writes /contact followed by their email address in Slack it automatically adds their email address to a MailChimp campaign list. This is great because you also wanted to encourage prospective attendees to sign up to your Slack team and by doing this they can also add themselves to your mailing list without any effort. The attendees are doing your work for you!

First, find or create everything you need:

  1. Obtain an App Connect on IBM Cloud® service. You can use an App Connect service that you already have or can sign up for App Connect.

    In this example, we use a new free App Connect - Lite plan service.

  2. Your team's Slack URL.
    Note: You need to be the owner of a workspace or have admin privileges.

    If you need to create a new workspace in Slack to have these privileges, see Create a new workspace and follow the instructions in the link.

  3. In Mailchimp, create a list, now known in the Mailchimp UI as an audience. Your Mailchimp list (audience) is where you store and manage all of your contacts. Give your list an appropriate name; for example, Coding events

Next, create your flow:

Using the IBM App Connect Designer authoring experience, you can create your flow from a template, or from scratch if you want to explore the steps taken to create a flow.

Creating the flow from a template

This enables you to create the flow immediately, and then select each node in the flow to validate the node and select the application accounts that you want to use. Search for the template name in your IBM App Connect / Templates view.

Restriction: Some templates are only available in App Connect on IBM Cloud
Figure 2. Tile for template, Add a Mailchimp subscriber from a Slack slash command
Tile for template, Add a Mailchimp subscriber from a Slack slash command

Template name: "Add a Mailchimp subscriber from a Slack slash command"

After creating a flow from the template, you can continue to test your flow.

Creating the flow from scratch

This enables you to explore the steps taken to create the flow from scratch, like to create the template.

Figure 3. Slack to Mailchimp flow diagram
Slack to Mailchimp flow diagram
    1. Log in to App Connect Designer.
    2. From the Dashboard, click New > Event-driven flow.
      Tip: As you progress, App Connect automatically saves your changes. If you navigate away from the flow at any stage, the flow is saved as a draft flow that you can complete at another time.
    3. Enter a name that identifies the purpose of your flow, for example: Mailing list sign up
      Figure 4. Entering a name for the flow
    4. Select Slack as your first application (source).
    5. Select New message as the Slack event that will trigger the action in MailChimp.
      Figure 5. Selecting the New message event for Slack
      Selecting the New message event for Slack
    6. If you haven't already connected a Slack account, click Connect to Slack and follow the instructions to allow App Connect to connect to your Slack account.
    7. A Callback URL is displayed. Click Copy to clipboard. We need this URL to configure a Slack slash command. The slash command is the trigger for the new message and it will send anything typed after it to the second application we connect in App Connect.
      Figure 6. The Callback URL shown for the Slack / New message event
      The Callback URL shown for the Slack / New message event
    8. Open a new browser tab and sign into your Slack workspace.
    9. Click the arrow next to your workspace name then click Add apps.

      In Slack, use the 'Add apps' option to add a new slash command

      In Slack, use the 'Add apps' option to add a new slash command
    10. In the Search App Directory field, search for ‘Slash Commands’.
    11. Click Install and then Add Configuration.
    12. In the Choose a Command field, type /contact and then click Add Slash Command Integration.
    13. In the Integration Settings section, update the following fields with the following details to create a Slack Slash Command:
      • URL: Paste the Callback URL you copied from App Connect earlier.
      • Method: POST
      • For the purposes of this tutorial, we'll leave all the other fields with the defaults.
      Figure 7. Slack integration settings to configure a new slash command for use with an App Connect instance
      Slack integration settings to configure a new slash command for use with an App Connect instance

      (Click image to view full size.)

    14. Click Save Integration.
    15. Go back to the flow you're creating in App Connect.
    16. Click the (+) and then select MailChimp > Add member to a list.
    17. If you haven't already connected a MailChimp account, click Connect to MailChimp and follow the instructions to allow App Connect to connect to your MailChimp account.
    18. In the Lists field, select your list (audience); for example, Coding events list.
    19. Click inside the Email Address field, then click the Insert a reference icon .
    20. Select the Message body object from the displayed list of objects. This will map the email address that the attendee types in to Slack (after the slash command) to the email address field in your MailChimp 'Coding events' list.
      Figure 8. Flow editor showing details of the Mailchimp action
      Flow editor showing details of the Mailchimp action
    21. That's all for this flow. From the banner, open the options menu [⋮] and click Start flow. Then click Dashboard to exit the flow.

Finally, test your flow:

  1. Go to any channel in your Slack workspace.
  2. Type /contact joeblogs@acme.com
  3. To confirm that the message has been sent, you'll see a Message published message in Slack.
    Figure 9. 'Message published' message in Slack
    'Message published' message in Slack

    Notice that it is only visible to you. This message will eventually disappear from your thread. As the message is only visible to your users they can be re-assured that nobody else will see their email address.

  4. Open MailChimp and click Lists > Coding events.
  5. You'll see the new addition in the list.
    Figure 10. New addition to the list in Mailchimp
    New addition to the list in Mailchimp

Assign your list to a campaign and the campaign will be sent to all the attendees who have added themselves to your contact list.

If you want to further enhance your experience, install the MailChimp app in Slack so that a notification is displayed in Slack informing you and the attendee that they have been added to the list.