Trigger a Slack notification when a Bolt run is overrunning

Introduction

This guide will show you how to set up an integration between Paradime and Slack using Paradime Webhooks and Zapier.

At the end of this tutorial, you will be able to trigger a custom Slack notification when a Bolt schedule is overrunning including details of the Bolt schedule.

Prerequisites

For this integration, make sure you have the following:

Create a new Zap in Zapier

To trigger an action each time a webhook event is delivered in Zapier, create a new Zap with Webhooks by Zapier as the Trigger and Catch Hook as the Event.

Press Continue, and copy the webhook URL. You will need this to connect Zapier to Paradime.

Configure a new Webhook in Paradime

In Paradime navigate to Account Settings and select Webhooks from the left Panel. Now you can click on + Add Endpoint to configure your webhook.

  • Enter the webhook URL generated by Zapier in the previews step

  • Add a description for your webhook integration (optional)

  • Filter to include in the event only the bolt.run.started event

When done, click on Create to setup the webhook.

Configure a Zapier delay

Now let's add a time delay before the pause the workflow for defined amount of time. Here we will set the threshold after which we will check if the Bolt schedule is still in progress.

Add a Delay by Zapier step in Zapier, choose the Delay For as the event type and configure your time delay. In the example below we are configuring to check the status of a Bolt schedule run after 120 minutes. Click Continue.

Store secrets

In the next step, to check the status of the Bolt schedule, you will need to generate the API credentials for your Paradime workspace.

Zapier allows you to store secrets. This prevents your keys from being displayed as plaintext in the Zap code. You can access them with the StoreClient utility.

  1. Create a Storage by Zapier connection

Go to https://zapier.com/app/connections/storage, create a new connection and save the UUID secret you generate for later.

  1. Add a temporary code step

Choose Run Python as the Event. Run the following code:

store = StoreClient('abc123') #replace with your UUID secret
store.set('API_KEY', 'abc123') #replace with the Paradime API KEY
store.set('API_SECRET', 'abc123') #replace with the Paradime API SECRET

Add a Zapier code action

Now lets add a code action that will allow us to call the Paradime API and check the status of the Bolt run. Choose Code by Zapier for the application and select Run Python for the event.

In the Set up action section, you will need to add three Input Data that we will use the python code.

  • API_QUERY: here you will add the Paradime API to check the status of the Bolt run and use the ID field from the previous Catch Raw Hook step as as below:

query BoltRunStatus {
        boltRunStatus(runId: <ID> ) {
        ok
        state
    }
}
  • API_ENDPOINT: here map this input to the Api Url field from the previous Catch Raw Hook step as as below.

  • START_DTTM: here map this input to the Start Dttm field from the previous Catch Raw Hook step as as below.

In the Code field, now lets add the following python code and replace YOUR_SECRET_HERE with the secret you created when setting up the Storage by Zapier integration.

This code action, will called the Paradime API and check the status of the Bolt run and the elapsed time of the Bolt run.

import json
import requests
from datetime import datetime

# Access secret credentials
secret_store = StoreClient('YOUR_SECRET_HERE')
api_key = secret_store.get('API_KEY')
api_secret = secret_store.get('API_SECRET')


# Fetch zapier input data
api_endpoint = input_data['API_ENDPOINT']
api_query = input_data['API_QUERY']
start_time_str = input_data['START_DTTM']

headers = {
    'X-API-KEY': api_key, 
    'X-API-SECRET': api_secret, 
    'Content-Type': 'application/json'
}

# Convert start_time_str to a datetime object
start_time = datetime.fromisoformat(start_time_str)
# Calculate elapsed time
current_time = datetime.utcnow() 
elapsed_time = int(round((current_time - start_time).total_seconds() / 60))  # Rounds to the nearest minute

# Call the Paradime API endpoint to check the status of the Bolt Run
response = requests.post(api_endpoint, headers=headers, data=json.dumps({'query': api_query}))
data = response.json()
status = data.get('data', {}).get('boltRunStatus', {}).get('state', 'UNKNOWN')

output = {
    'status': status,
    'elapsed_time': elapsed_time
}

Configure a Zapier filter

Now let's add a Zapier filter and let the Zapier workflow continue only if the Bolt run status == RUNNING. This will ensure that the next step where we will be posting a Slack message, is not going to be triggered if the Bolt run completed.

Add a Only continue if... step in Zapier, choose the Status field from the webhook response and filter for the condition to filer when status exactly match RUNNING.

Click Continue. If the example Bolt run for your Zap setup matches above state, a confirmation message will display, indicating the Zap will proceed.

Configure a Slack action

Finally lets setup the Slack integration and configure our Slack message. Select Slack as the App, and Send Channel Message as the Action.

In the Action section, choose which Channel to post to.

You can now configure the Message Text field and create your own template Slack message or use the one in the example below. You can use all the available input data from the Catch Raw Hook and the preview Zapier code action.

Slack message template
--- Replace the variables below with the Input Data in Zapier

⚠️ Bolt Schedule <{{run_url}} | *{{schedule__name}}*> is still running after {{elapsed_time}} minutes
>{{commands_command}}

🏢 _Workspace name:_ {{workspace__name}}

⏲️ _Started at:_ {{start_dttm}}

👤 _Owner:_ {{schedule__owner_email}}

🕹️ _Trigger:_ {{environment__actor}}

🪪 _RunID:_ {{id}}

ℹ️ <{{run_url}} | View run logs in Paradime>

Configure the other options with:

  • Send as a bot: Yes

  • Bot Name: Paradime

  • Bot Icon using this url:https://20146536.fs1.hubspotusercontent-na1.net/hubfs/20146536/logo-no-text-light-transparent-3x.png

Test and deploy your Zap

When done, you can click on Continue and Test your Zap, and finally click on the Publish button to go live. With this Zap, if a Bolt run is still Running after 120 minutes, a Slack notification will be posted to the selected Slack channel 🙌.

Last updated