Smart Slack commands via UiPath Studio Web process (Webhook trigger event, Data Service and Open AI have a party)

Intro

Hey everyone. I have recently created a small internal automation that manages a simple Slack command for internal purposes, and I figured it might be fun to share the concept with you via this small tutorial.

The process looks like this:

Prerequisites

There are a few important elements:

  • Slack app - I created a simple Slack app to manage my command and where I could pass my HTTP Webhook Event URL;

    But it can be any messaging app that works similarly.
  • Studio Web - it was the perfect match for my use case; it made the automation super quick to build and then publish for instant results
    • and a Webhook Event Happened trigger activity:
      image
      Given that it is currently in Preview, you will have to enable access to Preview packages in Studio Web via an Automation Ops Studio Web policy
  • Data Service (optional) - I already had my Data Service entity with some specific information I wanted to use as my input data set;
    In theory, this can be any input data set you want to use, and as long as it will fit in the instruction prompt of the Open AI. As such, technically you don’t need to store it in a Data Service entity. But for my purposes, it was easier this way because I could then use it across multiple processes and only update my data in one place.
  • Open AI - the missing piece was something that can parse my input data based on the user input (and some custom instructions) to generate the answer;
  • HTTP Request activity (WebAPI package) - it is used purely to deliver the response back to the user

What does it do?

To keep things fun for whoever will want to try it out (and also because I believe it to be super simple to build, but please let me know!), this time I will try to explain the general idea rather than going over all the details.

Let’s go :slight_smile:

Step 1 - User request

The flow of the process starts when the user issues a simple command from Slack:
/command [Your question]

This command is linked to a Slack app which in turn generates an API call to a specific endpoint. As you can imagine, it is the exact endpoint that we got from our Webhook Event Happened trigger activity:
image

If the process is published, this will automatically create an event trigger and start new jobs on each received API call from Slack API :slight_smile:

Extracting the user input

After the process is triggered and we get to see the actual payload, we will need to deserialize the JSON sent to us from Slack by using the Deserialize JSON activity.

Side note: To make it even simpler, our latest WebAPI 1.19.0-preview activity package delivers a way for you to provide a sample JSON structure, based on which you will get instant access to your JSON string objects during design time.

You can refer to the Slack API documentation for more details about the response structure, but it will look like this:

{
	(...)
    "command": "/getproductowner",
	(...)
    "text": "System Activities",
	(...)
	"response_url": "https://hooks.slack.com/commands/some/url/bits"
	(...)
}

Where:

  • the command tells you which command was issued by the user
  • the text tells you what they asked about
  • the response_url tells you where to send your reply back

Fetching the data from the Data Service entity

Because our use case requires us to provide some input data, and we already store it in a specific Data Service entity - let’s extract it!

This will happen in three simple steps:

  1. Get all records with a Query Entity Records activity.
    image
    This way we get instant access to our entity, but for not in a format that we need (a simple string with everything)
  2. Iterate over the output and add each row to a collection. In this case, we simply put a product tag and their owner as each new collection item:
    image
  3. Lastly, let’s combine our collection into a single string by using the Combine Text activity. Each record will then be separated by a new line:
    image

Kindly asking GPT4 chat completion for the answer

This is actually the simplest step. We will need an Open AI Chat Completion activity:
image

Same preview disclaimer as in the case of the webhook event trigger above.

And we will provide the user Slack command input and some custom instructions with our base data as the instructions:
image

It works better than one may expect :smiley:

Sending the answer back to the user

We reached the final step. We will now use the HTTP Request activity to send the reply. All we have to do is set it up with the response_url provided by the Slack API:
image

Add a Content-Type: application/json header:

And add our body in the response:

And this is it!

In my case, the process takes 10-15 seconds, the delay that I found to be linked mostly to the Data Service entity extraction step.

It works like this:

For the final process, I also added a bunch of improvements, after the users got to break it a bunch:

  • handle empty command prompts (some users sent nothing)
  • escape double quotes and ask GPT4 to not reply with any, because it was breaking the response_url payload
  • I also use a separate Data Service entity to log whenever users ask for something that was not there (so that I can improve my data set accordingly)
    These were not in the scope of this tutorial.

Please let me know if you gave it a try and it worked out well for you. I am always curious what our users are tinkering with! :slight_smile:

3 Likes

Hi! Amazing demo with the Slack app!

@loginerror Would it be possible to create a similar scenario where actual messages are sent to the newly created Slack app instead of using commands? I’m currently exploring this use case.

Thank you!

1 Like

Hi @DragosPadurariu

I think this falls under the Slack interactivity setup. I think it works similarly to what I’ve done above, where you can capture and trigger a UiPath automation based on an http trigger.

This Slack documentation page should give you more details how to set it up on Slack side:
https://api.slack.com/interactivity/handling

Hi, @loginerror - thanks for that!
We are planning to use the webhook slack trigger in production instance, do you know will it work as of now (March 2025) or since it is in preview mode it can only be used for demo purposes?

And 2nd question - is that trigger also available in regular Studio products or just the Studio Web ones?

Hi @salladinne

I believe I heard talks of the Webhook trigger activity finally going out of preview in the near future. Maybe @GuyVW will be able to offer better insights into the timeline.
For the record though - preview status does not mean that it can only be used for demo purposes; it just means that it is being actively developed and is subject to some smaller or bigger changes. But given that its been previewed for quite some time, my expectation is that the changes (if any) wouldn’t be really big.

As to the second question, it is also available on Studio Desktop:

The requirement is on Cloud and Integration Service, as it is those that handle the “listening” part of the webhook.