Looking to add Machine Learning to your Slack App? Algorithmia provides over 5000 individual algorithms, from simple utilities to advanced Deep Learning tools, which can be called via Slack Slash Commands or utilized by your Slack Bot Users.
Algorithmia + Slack Slash Commands
Algorithmia gives immense power to your Slack users and bots, thanks to its wide variety of tools and AI available via simple API calls. By invoking a Slash Command (
/commandname parameters) in Slack, users can trigger an abstract API to respond either immediately or via a delayed callback.
Here are just a few examples of how Slack users could utilize simple Slash Commands backed by Algorithmia:
- get a quick summary of all social shares for a URL
- automatically extract keywords from a document or webpage
- get immediate topic summaries from wikipedia
- colorize or stylize images
By adding just a little bit of glue code to pipeline one API into another, even more complex tasks are possible. For example, one could:
- connect to Dropbox and extract text from PDFs
- locate documents containing phrases similar to their search query
- crawl, scrape, analyze an entire website
Algorithmia + Slack Bot Users
Slack Bots take things a bit further, giving the user a chatbot-like context in which they can interact more naturally. In addition, Slack Bots can monitor channels/conversations to which they’ve been invited, allowing you to keep an eye out for important keywords, heightened emotional interactions, or images you need to log/analyze. By adding the power of Algorithmia to your Slack Bot, you could:
- create a long-term context for the user’s interactions, allowing them to train a facial recognition tool or a document classifier
- detect positive and negative sentiment in users’ messages, taking note of good experiences and offering to help with others, just as you would in any AI-driven chatbot
- ensure that images exchanged are safe for work
- observe the frequency of certain actions or keywords, to generate predictions and identify outliers
Sample code: use a Slack Slash Command to get a quick summary of any website
To demonstrate a very simple use of Algorithmia via Slack, let’s look at at how easy it is to create a Slach command which takes a web address and response with an auto-generated summary of that page’s content.
After you’ve followed Slack’s guide to create a Slack App, and read up on how Slash Commands work, head to your Slack App Management Page and click on the App name to see the details of our Slack App. Under “Basic Information”, copy the “Verification Token” – you’ll need it for the code below.
In order for your Slack App to connect to Algorithmia, you’ll need an intermediate function: and API endpoint which can accept a GET request from Slack, validate the content, and then POST to one of Algorithmia’s APIs. There are many ways to do this, but for simplicity I’ve chosen to create a simple NodeJS function which will can run as a Google Cloud Function, or be easily ported into your own NodeJS server:
SLACK_VERIFICATION_TOKEN with the Verification Token you copied in the prior step. Also replace
YOUR_API_KEY with your own Algorithmia API Key, if it isn’t there already.
Copy this code into your NodeJS app – if you’re using Google Cloud Functions, use an HTTP Trigger with the minimum memory allowed, and set the timeout to 300 seconds just in case some of your invocations run for a long time. Also be sure to add the following dependencies to your
Compile the function, and copy the web address of the API endpoint (in Google Cloud Functions, a URL similar to “https://us-central1-slack-helper-######.cloudfunctions.net/functionName”).
Now, head back to your Slack App Management Page, click your App name, and navigate to the “Slack Commands” section under “Features” on the left. Hit the “Create New Command” button. Call your command something like
/summarize and enter the URL you just copied into the “Request URL” box. Add a description such as “Summarizes a webpage”, and a hint such as “[web address]”.
Once you’ve saved this command, you can open up Slack and test out your new Slack Command! Just type
/summarize news.yahoo.com into any channel or conversation, and you should receive an immediate response of “processing”, followed by a summary of the days top news items.
Once you have that working, you may want to try out a more complicated example…
Sample code: call any Algorithmia algorithm from a Slack Slash Command
While you’ll generally want to create built-to-purpose commands which perfom a single action, the following example demonstrates some advanced techniques while gives your users immense power: once you’ve added it, they can call any of Algorithmia’s 5000+ algorithms.
Read through the comments in the code for tips and tricks, then try adding it as a new Slash Command called
algo and running it with
/algo nlp/SummarizeURL news.yahoo.com. You should get the same response as before… if so, you’re ready to try it with any other algorithm! Just replace
nlp/SummarizeURL with the full name of the algorithm, and
news.yahoo.com with the input you want to give it (even JSON).
Once you’ve mastered this, you’re ready to move on to more complex solutions, chaining multiple algorithm calles into a single function to accomplish large tasks, or designing a new Slack Bot to help your users out. Have fun, and connect with us anytime you’d like pointers or assistance!
See the NodeJS guide for an introduction to using the Algorithmia NodeJS client to call algorithms and manage data.
Your account can make up to 80 Algorithmia requests at the same time (this limit can be raised if needed).