Get Started Free
No time limit - totally free - just the way you like it.Sign Up Now
There are a plethora of Slack bots out there that are very powerful. Often times we get questions from management asking for information related to sales, customers and general information that we have in other dashboards or spread out across data sources such as Salesforce, S3, etc. This got me thinking, how can I make this easier not only for me, but for management to get the answers. I have used many bots and even created bots in the past to help solve similar problems, so why not use Dremio with Slack to get access to our data lake and make a bot that can answer these questions; Phrases such as “How many sales are in the south east?” or “How many prospects are in the POC phase?”
In this blog post we will examine how this implementation can be done using Dremio, Python and Slack bot APIs.
Slack has created a developer kit for their api which can be accessed here. Review the documentation, and in the next section we will look at how we integrated Dremio calls.
Let’s start by implementing a basic slack bot that will utilize the slash commands “/command”. The bot when called will display a dialog asking for the grain level for a report. When the user posts their response, the bot will call a function to run a query in Dremio, plot the results in Matplotlib and send the image back to the channel that the bot was called from.
I have made the code available for you to download here. The following breakdown shows details about each one of the steps that were executed during the implementation.
This file is used to set my environment variables at runtime and can be setup using the following code.
import os os.environ['SLACK_API_TOKEN'] = 'slack_bot_token_goes_here'
This is the main script that will be run. The bot will utilize Flask, a Python framework for a web server, to send and receive information to Slack. We begin by importing all of the necessary libraries and setting up the Dremio connection information. After creating the client and app we begin defining the endpoints that slack will call.
Now that you have a working bot, you can start adding your own custom functions. Maybe you want to use it for stocks and alerts. You could have your bot periodically query Dremio for the information and send out automated reports. You could even use Plotly and send back visualizations like in the example. There are endless possibilities when you have quick, easy access to your data!
To learn more about Dremio visit our tutorials and resources, also if you would like to experiment with Dremio on your own virtual lab, go ahead and checkout Dremio University, and if you have any questions visit our community forums where we are all eager to help.