<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Bitovi Blog - UX and UI design, JavaScript and Frontend development
Loading

DevOps |

Get more out of Slack with an AI-Powered GPT Chatbot [Free Slack App]

Enhance your team’s productivity and collaboration with an AI-powered GPT Slack bot. Deploy this free Slack app in minutes for a helpful new colleague.

Phil Henning

Phil Henning

Twitter Reddit

Have you ever wanted to create your own AI-powered chatbot for Slack? Wouldn't it be great to be able to prompt AI straight from a Slack message? Well, this blog is here to show you how you can easily do just that in minutes!

Why Use AI-Powered ChatBots?

In today's technology-based workplace, an AI-powered Slack chatbot can be an invaluable asset. By providing an easy to use and familiar interface, it can provide a number of advantages over traditional search engines:

  1. AI-powered ChatBots provide a familiar UI to interface with A.I. This makes it very simple for users to quickly and efficiently interact with the AI, allowing them to get the information they need without the need to understand complex coding.

  2. ChatBots can be used in place of or in conjunction with search engines to speed up knowledge acquisition. By having an AI-powered chatbot available, users can quickly and easily find the answers they need without having to search through multiple sources.

  3. ChatBots can be further specialized and enhanced with additional products such as Stackstorm to create unique and helpful workflows.

Implementation


Prerequisite

Event Summary

  1. A new message with a mention to the bot (@) is created in Slack
  2. The bot - A python script - reads this message and forwards it to the OpenAI API
  3. The OpenAI ChatGPT API replies, answer gets captured by the bot
  4. The bot creates a thread and post the answer

Instructions

1. ChatGPT fork

Begin by forking the bitovi/slack-bot-gptchat Github repo

2. Create a Slack App

slack-app

  • Click on “Create an app” and select “From scratch”

  • Give your app a name, select your Slack workspace

  • In Basic information > Add features and functionality. Click on “Permissions” and in Scopes, add in Bot Token Scopes: app_mentions:read ; channels:history ; channels:read ; chat:write

  • In settings, click on “Socket Mode”, enable it, and give the token a name. Copy the Slack Bot App Token (starts with xapp)

  • In Basic information > Add features and functionality. Click on “Event Subscriptions” and enable it. Furthermore, in “Subscribe to bot events,” select “app_mention”. Save changes.

  • Go to the “OAuth & Permissions” section and install your app to your workspace

  • Copy the Slack Bot Token (starts with xoxb), you'll add it to a GitHub repo secret called DOT_ENV.

Once the above Slack app is created make sure to “install the bot to your workspace

3. Obtain OpenAI API Key

The next step is to obtain the OpenAI API key. Why? Will need to connect to OpenAI’s API in order to use their GPT-3 API. If you are new to this, no problem. You’ll get 18$ for free without having to provide a credit card. To generate an API key, follow these steps:

  1. Go to the OpenAI API website
  2. Log in or sign up for an OpenAI account
  3. Go to the API Key section and create a new API key
  4. Copy the API key

4. Provide Slack and OpenAI keys to the app

Create a new secret in the repository's GitHub Secrets called DOT_ENV with the following contents:

OPENAI_API_KEY="sk-......."
SLACK_BOT_APP_TOKEN="xapp-......."
SLACK_API_KEY="xoxb-......."

Additionally, create the secrets AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for your AWS account.

5. Create a GitHub Action workflow file

The final step is to deploy the Slackbot onto an AWS EC2. We are going to make this a snap by utilizing the Bitovi GitHub Action: bitovi/github-actions-deploy-docker-to-ec2 which will handle the provisioning of AWS resources as well as the Slack bot deployment.

.github/workflows/deploy.yaml

name: Deploy

on:
  push:
branches: [ main ]

permissions:
  contents: read

jobs:
  EC2-Deploy:
    runs-on: ubuntu-latest
    environment:
      name: ${{ github.ref_name }}
      url: ${{ steps.deploy.outputs.vm_url }}
steps:
- id: deploy
  name: Deploy
  uses: bitovi/github-actions-deploy-docker-to-ec2@v0.4.6
  with:
    aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID}}
    aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
    aws_default_region: us-east-1

    # Provide a secret called `DOT_ENV` to append environment variables to the .env file
    dot_env: ${{ secrets.DOT_ENV }}

6. Verify the deployment

Screen Shot 2023-02-23 at 11.20.38 AM

slack-convo

By pushing this to your repo, the github workflow trigger: on.push.branches: [ main ] will create a new event that will start the above workflow.

If everything has been correctly set up above, then just wait for the deployment to run (~2 minutes), and the workflow will report (blue star) approved and provide a link to the EC2!



Having completed the above steps, you should now have:

  • A deployed Slack Bot

  • A connected Slack App ↔︎ Service (OpenAI)

  • A working chatbot for your team to use!

Conclusion

Deploying a AI-powered Slack ChatBot can be a great way to enhance your team’s productivity and collaboration. It can be used to automate mundane tasks, answer frequently asked questions and provide real-time support. By following the steps outlined above, you have easily deployed a AI-powered Slack ChatBot and are ready to make the most of your team's communication!

Need Help?

Drop into Community Discord and let us know! Bitovians (and our community) love to solve problems and chat about exciting projects.

Need DevOps Consulting or Platform Engineering services? Bitovi has DevOps consultants who can assist with all aspects of your development and DevOps journey.

 

Prompted, reviewed and edited by Bitovi, generated using the OpenAI platform.


Never miss an update!

Subscribe to the blog 📬

️ Subscribe