Slack

This is a quick setup guide to start sending Slack notifications with SuprSend.

1. Create SuprSend account

Simply signup on SuprSend to create your account. If you already have your company account setup, ask your admin to invite you to the team.


2. Integrate Slack and add option to join Slack in your product

To activate Slack Integration, you'll have to first enable slack channel from vendor page, create a Slack App and set up the right authentication method to take user permission for sending Slack notifications.


3. Test directly in Staging workspace

πŸ“˜

Since, Slack channel need the app integration beforehand for testing, you can only test it in Staging Workspace.


Different workspaces and their usage

You'll see 3 workspaces in your SuprSend account: Sandbox, Staging and Production. Workspaces can be switched from top navigation bar.

  • Sandbox is setup for quick testing with sample workflow, a sample user with your registered email and pre-configured channels (email, SMS, whatsapp, Inbox) for quick testing. It's ideal for quick exploration and testing and is available for limited period.
  • Staging is your development workspace. You'll do all your iterations and testing in this workspace before pushing it to production.
  • Production workspace is where you'll configure your live notifications and sync your actual product users. We do not recommend making changes directly in your production workspace. It will safeguard you from accidentally sending a test notification to your production users.

4. Create a workflow

Workflow houses the automation logic of your notification. Each workflow starts with a trigger, processes the defined logic, and sends one or more messages to the end user. You can create a workflow from SuprSend dashboard by clicking on "+ Create workflow" button on the workflows tab.


To design a workflow, you need:

  1. A Trigger point - Trigger initiates the workflow. You can initiate it
    • Using the direct workflow API, where you can include recipient channel information, preferences, and actor details directly in the trigger.
    • By emitting an event: You can trigger these events from your frontend application or from your backend systems, depending on the usecase. (note: the recipient needs to be pre-created for event-based triggers).

  1. Delivery node - Delivery nodes represent the channels where users will receive notifications. You can use multi-channel nodes to send messages across multiple channels, though it’s generally better to use smart channel routing to notify users sequentially rather than bombarding them on all channels at once.
  • Template in delivery node contains the content of the notification. You can add both static and dynamic content sourced from user properties or trigger payloads. We use JSONNET as Slack templating language. You can add dynamic content as data.var or data["$batched_events"][0].var (for batched alerts).


    Ensure to publish the template before using it in a workflow. Learn how to design Slack template here.


  1. Functional nodes (Optional) - These are the logic nodes in the workflow. You can use it to add delay, batch multiple notifications in a summary or add conditional branches in the workflow. Check out all workflow nodes here.

5. Trigger the workflow

You can trigger a test workflow directly from dashboard by clicking on "Test" button in your workflow editor or "Commit" changes to trigger it from your code. We follow Git like versioning for workflow changes, so you need to commit your changes to trigger new workflow via the API. You can check all methods of triggering workflow here.

To trigger a workflow, you need:

  1. Recipient - End user who would be notified in the workflow run. Recipient is uniquely identified by distinct_id within SuprSend and must have the relevant channel identity set in their profile. You can define recipient inline in case of API based trigger or create user profile first for event based trigger.

  2. Data or Event Properties - This will be used to render dynamic content in the template (added in template mock) or variables in the workflow configuration.

We'll be triggering the workflow with direct API trigger for quick testing. You can check all trigger methods here.


Sample Payload for API based trigger

You can get workspace key, secret or API key for trigger from Settings tab -> API keys . Here, we are defining Slack channel inline using user email and access token. The access token here belongs to the bot added to your Slack App during creation.

curl --request POST \
     --url https://hub.suprsend.com/trigger/ \
     --header 'Authorization: Bearer __api_key__' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "workflow": "_workflow_slug_",
  "recipients": [
      {
        "distinct_id": "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
        "$slack": [{
        "email": "[email protected]",
        "access_token": "xoxb-XXXXXXXX"
        }],
        "name":"recipient_1"
      }
    ],
  "data":{
      "first_name": "User",
      "invoice_amount": "$5000",
      "invoice_id":"Invoice-1234"
    }
}
'
from suprsend import Event
from suprsend import WorkflowTriggerRequest

supr_client = Suprsend("_workspace_key_", "_workspace_secret_")

# Prepare workflow payload
w1 = WorkflowTriggerRequest(
  body={
    "workflow": "_workflow_slug_",
    "recipients": [
      {
        "distinct_id": "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
        "$slack": [{
        "email": "[email protected]",
        "access_token": "xoxb-XXXXXXXX"
        }],
        "name":"recipient_1"
      }
    ],
    "data":{
      "first_name": "User",
      "invoice_amount": "$5000",
      "invoice_id":"Invoice-1234"
    }
  },
    idempotency_key = "_unique_identifier_of_the_request_"
  )

# Trigger workflow
response = supr_client.workflows.trigger(w1)
print(response)
const {Suprsend, WorkflowTriggerRequest} = require("@suprsend/node-sdk");
const supr_client = new Suprsend("_workspace_key_", "_workspace_secret_");

// Prepare workflow payload
const body = {
    "workflow": "_workflow_slug_",
    "recipients": [
      {
        "distinct_id": "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
        "$slack": [{
        "email": "[email protected]",
        "access_token": "xoxb-XXXXXXXX"
        }],
        "name":"recipient_1"
      }
    ],
    "data":{
      "first_name": "User",
      "invoice_amount": "$5000",
      "invoice_id":"Invoice-1234"
    }
}
const w1 = new WorkflowTriggerRequest(body, {
    idempotency_key: "_unique_identifier_of_the_request_"})

// Trigger workflow
const response = supr_client.workflows.trigger(w1);    
response.then(res => console.log("response", res));
package main

import (
  "log"
  suprsend "github.com/suprsend/suprsend-go"
)

// Initialize SDK
func main() {
  suprClient, err := suprsend.NewClient("_workspace_key_", "_workspace_secret_")
  if err != nil {
    log.Println(err)
  }
  _ = suprClient
  triggerWorkflowAPI(suprClient)
}

func triggerWorkflowAPI(suprClient *suprsend.Client) {

  // Create WorkflowRequest body
  wfReqBody := map[string]interface{}{
    "workflow": "_workflow_slug_",
    "recipients": []map[string]interface{}{
      {
        "distinct_id":  "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09",
        "$slack": [{
        "email": "[email protected]",
        "access_token": "xoxb-XXXXXXXX"
        }],
        "name":"recipient_1",
      },
    },
    // # data can be any json / serializable python-dictionary
    "data": map[string]interface{}{
      "first_name":    "User",
      "invoice_amount": "$5000",
      "invoice_id":"Invoice-1234",
      "spend_amount":  "$10",
    },
  }

  w1 := &suprsend.WorkflowTriggerRequest{
    Body: wfReqBody,
    IdempotencyKey: "_unique_identifier_of_the_request_",
  }
  // Call Workflows.Trigger to send request to Suprsend
  resp, err := suprClient.Workflows.Trigger(w1)
  if err != nil {
    log.Fatalln(err)
  }
  log.Println(resp)
}
package test;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONObject;

import suprsend.Suprsend;
import suprsend.SuprsendException;
import suprsend.WorkflowTriggerRequest;

public class Workflow {

  public static void main(String[] args) throws Exception {
    WorkflowTrigger();
  }

  private static void WorkflowTrigger() throws SuprsendException, UnsupportedEncodingException {
    Suprsend suprClient = Helper.getClientInstance();
    // payload
    JSONObject body = getWorkflowBody();
    String idempotencyKey = "_unique_request_identifier";
    WorkflowTriggerRequest wf = new WorkflowTriggerRequest(body, idempotencyKey, tenantId);
    //
    JSONObject resp = suprClient.workflows.trigger(wf);
    System.out.println(resp);
  }

  private static JSONObject getWorkflowBody() {
    JSONObject body = new JSONObject()
      .put("workflow", "__workflow_slug__")
      .put("recipients", new JSONArray()
           .put(new JSONObject()
                .put("distinct_id", "0gxxx9f14-xxxx-23c5-1902-xxxcb6912ab09")
                .put("$slack", new JSONObject()								 
                 .put("email", "[email protected]")
                 .put("access_token", "xoxb-XXXXXXXX"))
                .put("name", "recipient_1")
               ))
      .put("data", new JSONObject()
           .put("first_name", "User")
           .put("invoice_amount", "$5000")
           .put("invoice_id", "Invoice-1234")
          );

    return body;
  }
}

6. Check logs to see the status of your sent notification

Once triggered, you can monitor the request and it's status on the "Requests" tab, and view step-by-step debugging of each execution on the "Execution" tab inside workflow.


7. Push to Production

In SuprSend, each environment is isolated, meaning workflows, users, and vendors are configured separately in testing and production workspaces.

Follow this go live checklist to setup things in production once you are done testing.


What's next?