I made a slack app to submit helpdesk tickets directly from a form on Slack.
I implemented my app using the interactivity and shortcuts feature, API Gateway and Lambda. Here's an overview of how the app works:
- The user clicks on the shortcut to open up a form
- The lambda function receives an "shortcut" interaction, and uses the trigger_id to call the views.open method to send the form to the user
- User fills and submits the form
- Lambda function receives a "view_submission" interaction with the user inputs. The function parses the data sends a POST request to the helpdesk service that creates the ticket
The problem
The app is functional. However, it's required that the shortcut be pinned to the top of the shortcuts menu on a specific support channel on slack. According to this page, this is only seems possible for workflow shortcuts, not for app shortcuts.
So, I'm trying to refactor my app to be triggered by a custom workflow step instead of an app shortcut.
What I managed to do
When adding the workflow step to a workflow, the app needs to handle a workflow_step_edit interaction, send a configuration view, and then handle that view submission.
I'm doing all that with and empty configuration screen that receives no inputs.
from slack_sdk import WebClient
import boto3
import json
import base64
import urllib
import traceback
from datetime import datetime, timedelta
import requests
import os
SLACK_TOKEN_SECRET_NAME = os.environ.get('SLACK_TOKEN_SECRET_NAME')
FRESHSERVICE_TOKEN_SECRET_NAME = os.environ.get('FRESHSERVICE_TOKEN_SECRET_NAME')
FRESHSERVICE_DOMAIN = os.environ.get('FRESHSERVICE_DOMAIN')
SUPPORT_CHANNEL_ID = os.environ.get('SUPPORT_CHANNEL_ID')
def lambda_handler(event, _):
print(json.dumps(event))
# Base 64 decode the payload
payload = base64.b64decode(event['body'])
# Payload is URL encoded parameters, parse it
payload = payload.decode('utf-8')
payload = urllib.parse.parse_qs(payload)
payload = json.loads(payload['payload'][0])
print(json.dumps(payload))
# Create a WebClient
client = WebClient(token=get_secret_value(SLACK_TOKEN_SECRET_NAME)['token'])
# Invoke the correct method based on the callback id
try:
# User tries to add/edit the workflow step to a workflow
if payload['type'] == 'workflow_step_edit':
open_configuration_modal(payload, client)
# User submits the configuration
elif payload['type'] == 'view_submission' and payload.get('workflow_step'):
save_configuration(payload, client)
return {
'statusCode': 200,
'body': 'OK'
}
# User clicks on the shortcut
elif payload['type'] == 'shortcut': # Would be modified to handle the "workflow_step_execute" event
send_form(payload, client)
return {
'statusCode': 200
}
# User submtis the form
elif payload['type'] == 'view_submission':
create_ticket(payload, client)
return {
'statusCode': 200
}
except Exception as e:
print(traceback.format_exc())
return {
'statusCode': 500
}
def open_configuration_modal(payload, client):
# This step requires no configuration
# Send a basic view with a confirmation message
view = {
"type": "workflow_step",
"submit_disabled": False,
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "This step requires no configuration.",
}
}
]
}
# Send the view
client.views_open(
trigger_id=payload['trigger_id'],
view=view
)
def save_configuration(payload, client):
# There is no configuration to save
# Do a basic call to workflows.updateStep
client.workflows_updateStep(
workflow_step_edit_id=payload['workflow_step']['workflow_step_edit_id']
)
So, righ now I can add the workflow step to a workflow, and use the workflow to trigger my app with an "workflow_step_execute_event".
Where I'm stuck exactly
Unfortunately, the "workflow_step_execution" does not have a "trigger_id" that I can use to open my modal form. So I need a workaround to be able to open that form.
What I also tried
Also tried to ditch my custom form, and add the standard "Send a form" step of the Workflow Builder (not ideal), but I couldn't figure out how to configure my app to receive inputs from a previous step.
Possible solutions I'm looking for
Here are possible solutions to my problem
- A way to pin app shortcuts to the shortcut menus, so I don't even need to mess with workflow steps
- A way to send a trigger_id with the workflow_step_execute event, or any way to open my modal from a "workflow_step_execute" event
- Use the Workflow Builder's "Send a Form" step before my custom step, and configure my app to get the inputs from that form