Trigger Machine Learning Script
Leveraging the results of the Machine Learning tool in Action Flows can be pretty helpful. That's why we provide that automation solution that shows you how to trigger an ML script from a Slack message in a channel of your choice, including a Script snippet for the connection to the Action Flow.
Sample Action Flow
The image below shows two working Action Flows:
Watch a Slack Channel for a trigger phrase.
Trigger a Machine Learning script
Use Case Enhancements
If you want to pass parameters to the ML script, please check out this template: Forward Parameters to Machine Learning Script
If you want to return data to an Action Flow, please check out this template: Trigger an Action Flow from ML Workbench.
Configuring Action Flow
Below you will find the step-by-step guide for configuring each module of the above Action Flow.
1. Wait for Trigger phrase
To be able to trigger the ML script and Action Flows via Slack we use this module to keep track of all the messages in one specific private channel.
Configuration:
Action Flows Module: Slack
Action: Watch Private Channel Messages
Connection: Connect to your Slack account
Channel: Choose the channel from where you want to trigger the ML Script
2. Filter for Trigger phrase
We filter on the defined Trigger phrase to not trigger the ML script when sending random messages in the Channel.
Condition: {{Text}} from previous Slack module
Filter: Equal to (case insensitive) - Text operators
String variable: Enter text that is only used to trigger this AF (here: %%forecast)
String variable
In this context, %% or similar structures help to differentiate from other slack messages.
3. Customize Variables
This is the most important module in this Action Flow, where we have to adjust all the data specific to your team and account, like the team domain or an Application Key with the correct permissions.
Configuration:
Action Flows Module: Tools
Action: Set multiple variables
teamDomain: Enter your teamdomain, e.g. demo-action-flows
env: Enter your cluster, e.g. try, eu-1...
AppKey: For example, GjV6ODBvghgv6r76r0YzkyLTkxZwjbflqjwhebfljwhebfqjhebfwlV5TEVCcjMzAHBFK0F8TXdGBTlqBWFlsVPNk (create application key → Navigate to Permissions→ Select Machine Learning Permissions → Enable Use all Machine Learning Apps for your AppKey)
notebookId: We will add this one at a later point in this Template when creating a ML App / adding Scripts to an existing ML App
executionFileName: The name of the ML Script to be triggered, e.g. trigger_MLScript.ipynb
4. Trigger ML Script
This module sends a Post Request to our ML API and triggers a defined Script.
You do not have to change anything in this module!
Configuration:
Action Flows Module: HTTP
Action: Make a Request
URL: https://{{teamDomain}}.{{env}}.celonis.cloud/machine-learning/api/executions
Method: POST
Headers:
Name: Authorization
Value: AppKey {{AppKey}}
Body type: Raw
Content type: JSON (application/json)
Request content:
{ "notebookId": "{{notebookId}}", "executionFileName":"{{executionFileName}}" }
Setting an execution timeout
The request content can include an execution timeout. The JSON looks like this:
{ "notebookId": "notebookId", "executionFileName": "executionFileName", "executionTimeout": 24, "maxRetries": 0, "timeUnit": "HOURS" }
timeUnit can be “HOURS” or “MINUTES”.
Downloading Action Flow blueprints
To download blueprints for Action Flows, go to Marketplace. In the Marketplace page for your Action Flow, click the Download button to get the blueprint.
Blueprints can be imported into your Celonis Platform Team so that you can quickly make the required changes without needing to build the Action Flow from scratch.
Potential Alternatives
You could replace the triggering Slack module with a Scheduling to just run the ML Script frequently.
You could also replace the Slack module at the end with a messaging module of your choice e.g. Email or Microsoft Teams.
Possible Use Cases
Run complex Python scripts in Action Flows and use the results for different use cases
Integrate ML capabilities in your Action Flows