Integrate ChatGPT with Slack with few Easy Steps: Create your own Slack Chatbot

Danesh Ramuthi

Last Updated February 14, 2023

ChatGPT is an AI Conversational Model that can answer any user’s questions, from writing an essay to creating codes for applications.

Integrating ChatGPT with other apps will further enhance the effectiveness of an app and allow users to unlock a never before seen potential of the integrated app.

Today, we will learn about chatgpt and Slack integration and how you can create your slack chatbot.

It will be a more technical topic, but we have tried to make it as direct and actionable as we always do.

With this integration, you can use Slack, similar to ChatGPT. 

ChatGPT & Slack each have their own powerful features even without the integration, but combining these two apps together are just more beneficial.

It’s okay if you do not wish to integrate. It will be fine. 

chatgpt slack

But, if you are interested in learning more about chatgpt Slack integration, then this is the perfect article for you. 

Let’s make some magic. 

What is Slack?

chatgpt slack

Slack is an app designed for businesses that enable people to access the information they require through messaging. By unifying people and their efforts as a single team, Slack revolutionizes the way that companies communicate with one another.

It simplifies reaching out to colleagues, whether from within or outside of your organization, and facilitates collaboration as if you were working together in person. It also provides dedicated areas called channels, which help bring together the appropriate individuals and information for efficient teamwork.

Why Integrate ChatGPT with Slack?

chatgpt slack integration

Integrating ChatGPT with Slack can provide several benefits, including Improved functionality. You will be able to write a complete email with just a single line of prompts and send it to your colleagues instantly without spending hours creating the perfect email.

A Slack Bot or app integrated with ChatGPT can provide a competitive advantage. Integrating apps can help businesses differentiate themselves from their competitors by providing unique functionality and better user experiences.

Chatbot Slack Integration: Step by Step to Integrate ChatGPT/Chatbot with Slack

Utilize OpenAI & Slack API for ChatGPT Slack Integration

chatgpt slack

This tutorial utilizes the GPT-3 model, which closely resembles what is offered by ChatGPT. ChatGPT is essentially the predecessor of GPT-3 and will only require a single line of code change once it becomes available.

Step 1: Get Tokens by Registering an app with Slack

The initial step in integrating ChatGPT with Slack necessitates the registration of an app with Slack and the acquisition of both the Slack Bot Token and Slack App Token. Follow these instructions to accomplish this:

  1. Sign in to your Slack workspace
  2. Navigate to the Slack API website
  3. Choose “Create an app” and select “From scratch”
  4. Name your app and choose your Slack workspace
  5. In Basic Information > Add Features and Functionality, click on “Permissions” and add the following Bot Token Scopes: app_mentions:read, channels:history, channels:read, chat:write
  6. Click on “Socket Mode” in the Settings, enable it, and name the token. Copy the Slack Bot App Token (which begins with “xapp”).
  7. To activate it, click on “Event Subscriptions” in Basic Information > Add Features and Functionality. Select “app_mention” under “Subscribe to bot events,” then save changes.
  8. In the “OAuth & Permissions” section, install your app in your workspace.
  9. Finally, copy the Slack Bot Token (which begins with “xoxb”)

Step 2: Receive the OpenAI’s API Key

The subsequent stage is to obtain an OpenAI API key. This is necessary because to use OpenAI’s GPT-3 API, you must connect to their API. If you are a newcomer, don’t be concerned; you will receive $18 worth of free credits without having to provide a credit card. Follow these steps to generate an API key:

  1. Navigate to the OpenAI API website
  2. Sign up for an OpenAI account or log in if you already have one
  3. Go to the API Key section and generate a new API key
  4. Copy the API key

Step 3: Installing the necessary dependencies. 

This step is crucial to ensure that all the required libraries and tools are in place to enable the integration between ChatGPT and Slack to function properly. 

The specific dependencies required may vary based on your operating system and programming language, but common dependencies include the Slack SDK and OpenAI API client library.

After obtaining the necessary API keys, the subsequent step is to install the required dependencies, which include slack-bolt, slack, and openai. Slack-Bolt is a collection of tools and libraries that enable developers to create Slack applications quickly and easily. It offers a simple API for building bots, custom integrations, and Slack app features. To install these dependencies, run the following command in your terminal:

pip install openai

pip install slack-bolt

pip install slack

Step 4: Launch the Application

To run the application, you need to insert the three tokens (Slack Bot Token, Slack App Token, and OpenAI API Key) into the script provided below. This application listens to events in which the bot is tagged and responds by displaying a message indicating that the bot is working on an answer. The question is then sent to a GPT-3 model, and the resulting answer is returned to the user.

When you successfully execute the code to start the Bolt app, you will see a message “⚡️ Bolt app is running!” in your Python environment. This message is a signal that the app is currently active and functioning properly, ready to receive and process requests.

SLACK_BOT_TOKEN = “YOUR_TOKEN”
SLACK_APP_TOKEN = “YOUR_TOKEN”
OPENAI_API_KEY  = “YOUR_TOKEN”

import os
import openai
from slack_bolt.adapter.socket_mode import SocketModeHandler
from slack import WebClient
from slack_bolt import App

# Event API & Web API
app = App(token=SLACK_BOT_TOKEN)
client = WebClient(SLACK_BOT_TOKEN)

# This gets activated when the bot is tagged in a channel   @app.event(“app_mention”)
def handle_message_events(body, logger):
  # Log message
  print(str(body[“event”][“text”]).split(“>”)[1])

# Create prompt for ChatGPT
  prompt = str(body[“event”][“text”]).split(“>”)[1]

  # Let thre user know that we are busy with the request
  response = client.chat_postMessage(channel=body[“event”][“channel”],
                                  thread_ts=body[“event”][“event_ts”],
                                      text=f”Hello from your bot! :robot_face: \nThanks for your request,

I’m on it!”)

  # Check ChatGPT
  openai.api_key = OPENAI_API_KEY
  response = openai.Completion.create(
      engine=”text-davinci-003″,
      prompt=prompt,
      max_tokens=1024,
      n=1,
      stop=None,
      temperature=0.5).choices[0].text

   # Reply to thread
  response = client.chat_postMessage(channel=body[“event”][“channel”],
                                  thread_ts=body[“event”][“event_ts”],
                                      text=f”Here you go: \n{response}”)

if __name__ == “__main__”:
  SocketModeHandler(app, SLACK_APP_TOKEN).start()

Step 5: Test the Outcome

Congratulations! The final step is to add your bot to a channel in the integration tab. This will allow the bot to receive messages and respond to queries in that particular channel. 

Use GitHUB Repository to create a Slack Chatbot

slack chatgpt

A user named pedroporito at Github has detailed steps to integrate ChatGPT with Slack in his own personal project that are not officially affiliated with ChatGPT or Slack.

Basically the steps are as follow: 

  1. Install the required dependencies.
  2. Set the environment variables CHATGPT_EMAIL and CHATGPT_PASSWORD with your OpenAI credentials.
  3. Set the environment variables SLACK_SIGNING_SECRET and SLACK_BOT_TOKEN after creating the Slack App.
  4. Run the app.py script to start the bot.

Once the bot is running, it will be able to listen for and respond to messages in Slack.

 The ChatGPTConfig dictionary in the app.py script contains settings for the revChatGPT package, which includes the email and password for the OpenAI account that the bot will use to authenticate with the GPT-3 API. These values are taken from the CHATGPT_EMAIL and CHATGPT_PASSWORD environment variables.

The conversation_id parameter in the Chatbot constructor determines the ID of the conversation that the bot will use. If this parameter is not provided, the revChatGPT package will create a new conversation ID for each message that the bot receives.

To use the app.py script, it is important to note that it exposes port 4000 for Slack events by default. However, you can change the port number by modifying the corresponding code in the script.

To configure the Slack App for the bot, you can follow the example instructions provided on the official SlackApi GitHub account. In the OAuth & Permissions section, the required Scopes for the bot are: “app_mentions:read”, “chat:write”, and “im:write”. In the Event Subscriptions section, you need to subscribe to the “app_mention” event.

You can find the relevant codes here at GitHub

Integrate ChatGPT with Slack using Zapier

slack chatgpt

Zapier is a tool that automates tasks between different web applications, allowing users to easily transfer information and data without manual input. This can help users save time and focus on their more important tasks.

For this integration, Zapier offers a no-code solution to automatically transfer information between OpenAI (ChatGPT) and Slack.

Besides, Zapier provides more than just connecting two apps together. You can automate complete processes from start to finish with it.

What does Zapier’s ChatGPT & Slack Integration does?

Here are some of the supports and triggers from this integrations: 

chatgpt slack

ChatGPT and Slack Bot Integration will allow you to check moderations, send prompts, generate images, send prompts, search embeddings and more.

This is a brief overview of how OpenAI (ChatGPT) and Slack integrations work on Zapier:

  1. Authenticate OpenAI (ChatGPT) and Slack.
  2. Choose the trigger app that will start the automation.
  3. Select the resulting action in the other app.
  4. Choose the data that you want to transfer between the two apps.

 Click here to connect your ChatGPT with Slack using Zapier

Add Chatbot directly from Slack: Instantly Create own Slack Bot

One of the simplest ways you can get a ChatGPT like experience in your slack is to add an integration directly from Slack Website.

Simply login to your slack and choose your workspace. Later, add the Chatbot from this link. That’s it, you are done. You can now use Slack in a Chatbot kinda style.

ChatBot is a tool that enables the creation of powerful chatbots for various services. The chatbot can be integrated with different platforms, including Slack, Facebook, and LiveChat, or used on a website with the Chat Widget.

Use Albus to Integrate ChatGPT With Slack

Albus is basically an API that you have to use to integrate ChatGPT with Slack and its designed for everyone.

It sounds like Albus is a chatbot that you can message to ask questions and get solutions.

Once you have integrated Albus, you can include Albus in your channels/direct messages and use the @albus command to inquire & obtain an immediate response within the group.

Marketers can use Albus in producing customized and captivating content for their intended audience. By generating tailored replies to client queries, Albus can enhance customer satisfaction and establish credibility.

Not only for marketers, but Albus can also aid sales professionals in producing personalized responses to client inquiries and crafting captivating marketing content.

Pricing of Albus is $1.99 per month for 0-50 users and $19.99 per year. 

More detailed pricings and Get your Albus API here.

FAQs

1. How do I add ChatGPT to Slack?

You can add ChatGPT to Slack through OpenAI’s API and Slack API and by using third-party integration tools like Zapier and Albus.

2. How do I integrate chat bot with Slack?

Detailed steps to integrate chat bot with Slack have been explained here. But to summarize, you can download a Chatbot directly from Slack without using any APIs.

3. Is there a notepad for Slack?

Currently, there is no built-in notebook available in Slack, but you can use Zoho Integration or use posts in Slack to write notes.

4. How do I write notes in Slack?

You can use posts in Slack to write notes. When sharing lengthy content such as project plans or meeting notes, a simple message in Slack may not suffice. This is where the feature of creating posts comes in handy. Posts enable you to collaborate and share fully-formatted documents with your team members in Slack. With this feature, you can easily share long-form content and collaborate on it without having to switch to another tool or application. You can format your content in any way that suits your needs, add images, and even include code snippets. By creating posts, you can enhance your team’s collaboration and streamline your workflow, making it easier to get work done. So, if you need to share lengthy documents with your team, consider creating a post in Slack to keep everyone on the same page.

5. Can I write Markdown in Slack?

It can be confusing, but Slack’s text formatting differs from standard Markdown syntax. While Markdown syntax for bold styling typically involves using a single asterisk, only underscores are supported in Slack. Also, standard Markdown syntax is not supported if the WYSIWYG editor is enabled. Therefore, to add bold styling in Slack, you should use underscores instead of asterisks. While this may take a bit of getting used to, it is a small tradeoff for the many benefits of using Slack for team communication and collaboration.

6. Does Slack have a whiteboard?

Slack does not have a built-in white board feature, but you can very easily use the whiteboard in Slack using SketchTogether. SketchTogether is a powerful online whiteboard tool that enables teams to collaborate in real time on visual content such as drawn mockups, annotated screenshots, and meeting notes, all from within their web browser.

Is there Grammarly for Slack?

Although Grammarly is not natively integrated with Slack, there is a way to use the two programs together by installing Grammarly for Windows or Mac. Once you have installed the software, you can use Grammarly to check your written content for grammar and spelling errors across various platforms, including Slack. This can be incredibly useful, especially if your team primarily communicates through Slack written messages. Using Grammarly in conjunction with Slack, you can ensure that your messages are free of errors and convey your intended meaning clearly and effectively. So if you’re a heavy Slack user, it’s definitely worth considering installing Grammarly to help improve your written communication.

Final Thoughts

In conclusion, integrating ChatGPT with Slack can greatly enhance the efficiency and productivity of teams by providing quick and accurate responses to common queries. From setting up a custom chatbot to using pre-built integrations and APIs, there are various ways to seamlessly integrate ChatGPT with Slack. By leveraging the power of AI and natural language processing, ChatGPT can help teams automate routine tasks and streamline their workflows, allowing them to focus on more strategic and creative endeavors. So whether you’re a small business or a large enterprise, integrating ChatGPT with Slack is definitely worth considering if you want to improve your team’s collaboration and communication.

Found that helpful? Get similar posts and other exclusive AI information that we only share with our email subscribers?

Subscribe to our email to get lightning fast AI information right to your Inbox Button

Table of Contents

Thanks for Reading!

ai

Danesh Ramuthi

Tech Content Writer

Danesh is a scientist and a content writer with more than 2 years of experience. He is also a published author of a science fiction children’s book titled Imaginary Tales. 

AI has always been in his mind and soul ever since the cult classic movie 2001: A Space Odyssey inspired him to become a writer. Seeing a lot of stigma and misconceptions on AI, he has decided to found Ava Machina as an Hub for people from different backgrounds to gather and learn about AI through expert insights as well as redirecting them to the right source.

Leave a Comment

Your email address will not be published. Required fields are marked *