In our first ever live hackathon, we dove into some of the more advanced capabilities in iconik using our API and other modern technologies.
Our goal was to enable a custom workflow where items that are flagged with certain metadata cannot be shared. We also wanted to use a third party messaging app to notify when this restriction occurred.
We were able to build the entire integration from scratch in about two hours using a mix of Google Cloud Functions and Slack’s API, along with iconik’s built in webhooks and API.
If you would like to watch the whole thing, you can watch it here:
00:06:05 Explaining the problem we’re solving with Slack integration.
00:14:54 Creating a webhook
01:07:58 Setting up could functions
01:11:30 Creating a Slack app
01:35:55 Posting data from iconik into Slack
01:55:51 It compiles! Let’s celebrate.
Since the live stream, I’ve gone and made a few very small changes to the code so that any iconik admin can just install this and use it themselves.
Here’s how you can do it.
The first thing you need to do is grab the code for your cloud function from our Github page
You will first need to do a few things in iconik, Google, and Slack to get this going. Let’s start with what we need to do in iconik. We need to build a metadata field to use as a trigger.
Once you have added the field, you will need to:
Make sure that this view is available in the assets category. Once it is, you can validate by going to an asset as any user with rights to see the view and validate it exists.
The last thing we need to do with our view is to copy the view ID for use later.
We also need to create a new App-ID and authorization token for talking back with the API. This App-ID should run as a user that has the appropriate roles and ACLs to see/manipulate all assets in the system.
Also, click CREATE to get your new token for this app-id.
Remember: This token is only available once from this page, so make sure you copy it and the app-id and paste them somewhere for use later. You won’t be able to get it back once you browse away.
For now, we are done in iconik.
Let’s move on to Slack to enable our app to send messages to a channel. Point your browser to https://api.slack.com/apps and create a new app.
Once you have created the new app, we need to add an incoming webhook feature.
Click “incoming webhooks” on the next screen.
On this screen, you will need to Active Incoming Webhooks first, and then click “Add New Webhook to Workspace”.
Next, you get to select which channel to post the messages into. Choose the appropriate channel here and hit “allow”.
Once this is complete, you will have a Copy button at the bottom of the next screen with the webhook URL for slack. Also, save this for later. We will need it for our cloud function as well.
Now we are done with our setup in Slack.
Next up, we need to create our Google Cloud function. Log into your GCP account at https://console.cloud.google.com and browse to Cloud Functions from the menu. If you do not have access to cloud functions, you may need to add them to your project or have an administrator for your GCP domain allow you to do this.
From the Cloud Function menu, we need to create a new cloud function.
On the next screen, we need to do three important things
Save this and click Next to go to step 2— the code.
In this view, you will see a few things you need to change
Next, you need to add one line to your requirements.txt doc.
Now hit deploy. This will take a little while to complete, but if you did everything correctly you should get a successful deployment. Click back into the successfully deployed function, click on the trigger tab, and copy your cloud function URL.
The very last thing you need to do will be to create the webhook in iconik.
To give it a try:
If all is working, you will get a Slack notification shortly after the share is created, and if you refresh the page, you will see the share is deleted.
Also, try doing the same with an asset that doesn’t have this flag enabled. Shares should work as expected!