Slack Bot That Summarizes Articles

At Midio, like most companies, we constantly share links to articles in various Slack channels. However, we don't have an established routine of including a summary of the posts we share. We decided to create a Slack bot in Midio to automate this for us!

In this guide, you will learn how to build a Slack bot that summarizes an article and posts it as a reply in the relevant thread.

Demo

The Slack bot in action

Prerequisites

  • Midio account (you can create one here)

  • Slack account and workspace

  • API key for Tavily. This is the API used to extract content from links. You can get a free key for up to 1,000 API credits / month

Setting up the Slack bot

Select From manifest and paste in this manifest:
{
    "display_information": {
        "name": "Article summarizer"
    },
    "features": {
        "bot_user": {
            "display_name": "Article summarizer",
            "always_online": true
        }
    },
    "oauth_config": {
        "scopes": {
            "bot": ["chat:write", "channels:history"]
        }
    },
    "settings": {
        "event_subscriptions": {
            "request_url": "<https://example.com/event>",
            "bot_events": ["message.channels"]
        },
        "org_deploy_enabled": false,
        "socket_mode_enabled": false,
        "token_rotation_enabled": false
    }
}

Take notice of request_url in event_subscriptions. After creating a Midio project, you have to change its value to <your-project-name>.midio.app/event

  • After creating the bot, go to OAuth & Permissions and click on Install to workspace. This will create a Bot User OAuth Token, which we will use to post a summary to a thread.

  • Invite the bot by running the following command in a channel: /invite @Article summarizer

Summarize article with Midio

Create a new project in Midio by clicking New project in the Dashboard. In the dialogue, choose the Slack Article Summarizer template.

The template sets up a workflow that summarizes an article if it finds a URL in a user message. This workflow utilizes an LLM agent that receives the content of the article and summarizes it into a Markdown-formatted text.

How it works

The workflow has a Parse event function that parses the Event payload received from Slack and retrieves the URL in the posted message. This URL is then passed to the Extract function in the Tavily package, which will extract the content in the web page. The raw content and the images are passed along to Chat Complete, along with the following prompts:

**system message**
You are a summarizer agent, specialized in summarizing articles from web pages.
You will be provided the raw content from a web page and urls to images 
in the web page.

The summary should cover all the key points and main ideas presented in 
the original text, while also condensing the information into a concise 
and easy-to-understand format.
The summary should be limited to 200 words.
You will output the summary in Markdown, with a header and sub-headers 
where it is needed.

Please ensure that the summary includes relevant details and examples 
that support the main ideas, while avoiding any unnecessary information 
or repetition.

The length of the summary should be appropriate for the length and 
complexity of the original text, providing a clear and accurate overview
without omitting any important information.

Inline one image that is relevant to the article. If you can not find 
such an image, you do not need to include an image.

**user message** (in Midio's expression language)
****"Urls to images from page: ${images}\\n
Summarize this text:\\n${content}"

Note the difference between the system message and user message. In user message, Midio’s expression language is used. This enables us to send images and content as input to the string formatting.

The workflow maintains a list of allowed Slack channel IDs, and will only process events from these. You can configure these yourself in the editor, by modifying the Data object that is sent to Should process event. After verifying that it should process the event, the workflow posts a message as a thread notifying that it is creating a summary. It will update the previously sent message with the summary after it is done summarizing.

Deploy the application

It’s time to deploy the application directly from Midio! You can do this by clicking the hamburger menu on the top-left panel, and selecting Deploy app in the dropdown menu. Make sure you have modified the Event request URL in the Slack configuration to <your-project-name>.midio.app/event.

After deploying the app, verify that it works by pasting a link in the Slack channel where you added the bot.

Next steps

You now have a bot that can summarize articles for you! However, this is just the beginning.

Here are some suggestions for enhancements:

  • Enable interactivity with Slack’s Slash commands. Maybe users can suggest more clarifications on the summary that the bot posted?

  • Create a weekly newsletter with all the summaries that the bot has posted that week. Explore the Ephemeral Store module for memory-based state management.

Last updated

Was this helpful?