Skip to main content

Check out Port for yourselfย 

Ingest and map Slack users to Port user accounts

This guide demonstrates how to ingest Slack users into your Port software catalog and automatically map them to existing Port user accounts based on email addresses.

We will leverage on Port's custom webhook integration, self-service actions and automations to ingest data from Slack and map them to Port user accounts.

Once implemented users will be able to:

  • Maintain a complete inventory of all Slack users in your organization within Port.
  • Automatically link Slack users to their corresponding Port user accounts for seamless integration.
  • Provide visibility into which Slack users have Port accounts and which don't.

Prerequisitesโ€‹

This guide assumes the following:

  • You have a Port account and have completed the onboarding process.
  • You have a Slack workspace with admin permissions to create apps and generate bot tokens.
  • You have permissions to create blueprints, self-service actions, and automations in Port.

Set up data modelโ€‹

To represent Slack users in your portal, we need to create a Slack User blueprint that can store Slack user data and optionally link to Port user accounts.

Create the Slack User blueprint

  1. Go to the data model page of your portal.

  2. Click on + Blueprint.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following JSON schema:

    Slack user blueprint (Click to expand)
    {
    "identifier": "slack_user",
    "description": "Slack User",
    "title": "Slack User",
    "icon": "Slack",
    "schema": {
    "properties": {
    "tz": {
    "type": "string",
    "description": "The user's time zone."
    },
    "is_restricted": {
    "type": "boolean",
    "description": "Indicates if the user is restricted."
    },
    "is_primary_owner": {
    "type": "boolean",
    "description": "Indicates if the user is the primary owner."
    },
    "real_name": {
    "type": "string",
    "description": "The user's real name."
    },
    "team_id": {
    "type": "string",
    "description": "The user's team ID."
    },
    "is_admin": {
    "type": "boolean",
    "description": "Indicates if the user is an admin."
    },
    "is_app_user": {
    "type": "boolean",
    "description": "Indicates if the user is an app user."
    },
    "deleted": {
    "type": "boolean",
    "description": "Indicates if the user is deleted."
    },
    "is_bot": {
    "type": "boolean",
    "description": "Indicates if the user is a bot."
    },
    "email": {
    "type": "string",
    "title": "Email",
    "description": "The user's email address"
    }
    },
    "required": []
    },
    "mirrorProperties": {},
    "calculationProperties": {},
    "aggregationProperties": {},
    "relations": {
    "user": {
    "title": "Port User",
    "target": "_user",
    "required": false,
    "many": false
    }
    }
    }
  5. Click on Save to create the blueprint.

Add Port secrets

Now let's add your Slack bot token to Port's secrets:

  1. Click on the ... button in the top right corner of your Port application.
  2. Click on Credentials.
  3. Click on the Secrets tab.
  4. Click on + Secret and add the following secret:
    • SLACK_BOT_TOKEN - Your Slack bot token with users:read and users:read.email scopes. How to get the token

Set up webhook integrationโ€‹

We'll create a webhook integration that can ingest multiple Slack users at once and automatically establish relationships with existing Port users.

Follow the steps below to create the webhook integration:

  1. Go to the Data Sources page.

  2. Click on + Data Source.

  3. Select Webhook and click on Custom integration.

  4. Name it "Slack Users Sync".

  5. Copy the webhook URL - you'll need this for the automation.

  6. Copy and paste the following mapping into the Map the data from the external system into Port field:

    Slack users webhook mapping (Click to expand)
    [
    {
    "blueprint": "slack_user",
    "operation": "create",
    "filter": "(.body.response | has(\"members\")) and (.body.response.members | type == \"array\")",
    "itemsToParse": ".body.response.members | map(select(.deleted == false))",
    "entity": {
    "identifier": ".item.id | tostring",
    "title": ".item.name | tostring",
    "properties": {
    "tz": ".item.tz",
    "is_restricted": ".item.is_restricted",
    "is_primary_owner": ".item.is_primary_owner",
    "real_name": ".item.real_name",
    "team_id": ".item.team_id",
    "is_admin": ".item.is_admin",
    "is_app_user": ".item.is_app_user",
    "deleted": ".item.deleted",
    "is_bot": ".item.is_bot",
    "email": ".item.profile.email"
    },
    "relations": {
    "user": {
    "combinator": "'and'",
    "rules": [
    {
    "property": "'$identifier'",
    "operator": "'='",
    "value": ".item.profile.email"
    }
    ]
    }
    }
    }
    },
    {
    "blueprint": "slack_user",
    "operation": "create",
    "filter": ".body.response.user != null",
    "entity": {
    "identifier": ".body.response.user.id | tostring",
    "title": ".body.response.user.name | tostring",
    "properties": {
    "tz": ".body.response.user.tz",
    "is_restricted": ".body.response.user.is_restricted",
    "is_primary_owner": ".body.response.user.is_primary_owner",
    "real_name": ".body.response.user.real_name",
    "team_id": ".body.response.user.team_id",
    "is_admin": ".body.response.user.is_admin",
    "is_app_user": ".body.response.user.is_app_user",
    "deleted": ".body.response.user.deleted",
    "is_bot": ".body.response.user.is_bot",
    "email": ".body.response.user.profile.email"
    },
    "relations": {
    "user": {
    "combinator": "'and'",
    "rules": [
    {
    "property": "'$identifier'",
    "operator": "'='",
    "value": ".body.response.user.profile.email"
    }
    ]
    }
    }
    }
    }
    ]
  7. Click on Save.

Set up self-service actionsโ€‹

We'll create two self-service actions in this section, one for fetching Slack users and another for fetching a Slack user via email for the automation and webhook to ingest data.

Sync Slack Users self-service action

This action fetches all Slack users and send them to the process Slack users automation for processing. The automation will then send the response to the webhook for ingestion.

Follow the steps below to create the action:

  1. Go to the Self-service page.

  2. Click on + Action.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following action configuration:

    Sync Slack Users action (Click to expand)
    {
    "identifier": "sync_slack_users",
    "title": "Sync Slack Users",
    "icon": "Slack",
    "description": "Fetch and sync all Slack users to Port",
    "trigger": {
    "type": "self-service",
    "operation": "DAY-2",
    "userInputs": {
    "properties": {},
    "required": [],
    "order": []
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://slack.com/api/users.list",
    "agent": false,
    "synchronized": true,
    "method": "GET",
    "headers": {
    "RUN_ID": "{{ .run.id }}",
    "Content-Type": "application/json",
    "Authorization": "Bearer {{ .secrets.SLACK_BOT_TOKEN}}"
    },
    "body": {}
    },
    "requiredApproval": false
    }
  5. Click Save to create the action.

Get Slack user by email self-service action

This action fetches a single Slack user by email and send the response to a process single slack user automation for processing. The automation will then send the response to the webhook for ingestion.

Follow the steps below to create the action:

  1. Go to the Self-service page.

  2. Click on + Action.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following action configuration:

    Get Slack user by email action (Click to expand)
    {
    "identifier": "get_single_slack_user",
    "title": "Get Slack User by Email",
    "icon": "Slack",
    "description": "Fetch a Slack user to Port",
    "trigger": {
    "type": "self-service",
    "operation": "DAY-2",
    "userInputs": {
    "properties": {
    "email": {
    "icon": "DefaultProperty",
    "type": "string",
    "title": "Email of user",
    "description": "Email of the slack user"
    }
    },
    "required": [],
    "order": [
    "email"
    ]
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://slack.com/api/users.lookupByEmail?email={{ .inputs.email }}",
    "synchronized": true,
    "method": "GET",
    "headers": {
    "RUN_ID": "{{ .run.id }}",
    "Content-Type": "application/json",
    "Authorization": "Bearer {{ .secrets.SLACK_BOT_TOKEN}}"
    },
    "body": {}
    },
    "requiredApproval": false
    }
  5. Click Save to create the action.

Set up automationsโ€‹

Now we'll create the automations that process the Slack users list and sends the response to the webhook for bulk ingestion and single user ingestion.

Create automation to bulk ingest Slack users

This automation will trigger when the Sync Slack Users action is executed. It will then process the Slack users list and send the response to the webhook for bulk ingestion.

Follow the steps below to create the automation:

  1. Go to the Automations page of your portal.

  2. Click on + Automation.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following automation configuration:

    Process Slack users automation (Click to expand)
    Replace the webhook URL

    Replace the webhook URL with the one you created in the previous step.

    {
    "identifier": "process_slack_users",
    "title": "Process Slack Users",
    "description": "Processes Slack users list and sends to webhook for bulk ingestion",
    "icon": "Slack",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "RUN_UPDATED",
    "actionIdentifier": "sync_slack_users"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.status == \"SUCCESS\"",
    ".diff.after.response.ok == true"
    ],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "<YOUR_WEBHOOK_URL>",
    "agent": false,
    "synchronized": true,
    "method": "POST",
    "headers": {
    "Content-Type": "application/json"
    },
    "body": {
    "response": "{{ .event.diff.after.response }}"
    }
    },
    "publish": true
    }
  5. Click Save to create the automation.

Create automation to process single Slack user

This automation will trigger when the Get Slack user by email action is executed. It will then process the Slack user and send the response to the webhook for single user ingestion.

Follow the steps below to create the automation:

  1. Go to the Automations page of your portal.

  2. Click on + Automation.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following automation configuration:

    Process single Slack user automation (Click to expand)
    {
    "identifier": "process_single_slack_user",
    "title": "Process Single Slack Users",
    "description": "Processes Slack user and sends to webhook for ingestion",
    "icon": "Slack",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "RUN_UPDATED",
    "actionIdentifier": "get_single_slack_user"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.status == \"SUCCESS\"",
    ".diff.after.response.ok == true"
    ],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "<YOUR_WEBHOOK_URL>",
    "agent": false,
    "synchronized": true,
    "method": "POST",
    "headers": {
    "Content-Type": "application/json"
    },
    "body": {
    "response": "{{ .event.diff.after.response }}"
    }
    },
    "publish": true
    }
  5. Click Save to create the automation.

Create automation to sync Slack users when a new Port user is added

To ensure new Port users get mapped to Slack users automatically, we'll create an automation that triggers when a new Port user is created. This automation will trigger the Get Slack user by email action to fetch details of the Slack user by email and trigger the process single slack user automation for processing.

Follow the steps below to create the automation:

  1. Go to the Automations page of your portal.

  2. Click on + Automation.

  3. Click on the Edit JSON button in the top right corner.

  4. Copy and paste the following automation configuration:

    Automation to sync Slack users when a new Port user is added (Click to expand)
    {
    "identifier": "ingest_slack_user",
    "title": "Trigger slack_user ingestion automation",
    "description": "This will call the webhook endpoint to ingest a single slack user",
    "icon": "Slack",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "ENTITY_CREATED",
    "blueprintIdentifier": "_user"
    },
    "condition": {
    "type": "JQ",
    "expressions": [],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://api.getport.io/v1/actions/get_single_slack_user/runs",
    "agent": false,
    "synchronized": true,
    "method": "POST",
    "headers": {
    "RUN_ID": "{{ .run.id }}",
    "Content-Type": "application/json"
    },
    "body": {
    "properties": {
    "email": "{{ .event.diff.after.identifier }}"
    }
    }
    },
    "publish": true
    }
  5. Click Save to create the automation.

Let's test itโ€‹

  1. Go to the Self-service page.

  2. Find the "Sync Slack Users" action.

  3. Click Execute.

  4. Monitor the action execution in the Audit logs page.

  5. Verify that Slack users are created in your catalog with proper relationships.

  6. Verify that the Slack user is created in your catalog with proper relationships.

Conclusionโ€‹

You've successfully ingested Slack users into your Port catalog and automatically mapped them to existing Port user accounts based on email addresses.