Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

One-Click Deployment

Easily get a copy and launch your app on AirCode by clicking the button below.

Deploy with AirCode


Build a Slack ChatGPT App with JavaScript, including full source code, free hosting, and step-by-step tutorial.

This article helps you quickly implement a Slack chatbot and integrate ChatGPT capabilities into it. You can ask it questions directly or mention it in a group chat to get ChatGPT's answers. (The following are screenshots of the effect)

What you will learn from this article

  1. Create a Slack bot and configure the events and permissions required for the bot
  2. Use AirCode to implement the chat capabilities of the bot
  3. Integrate the bot with ChatGPT capabilities

Step 1: Create a Slack bot

  1. Go to the Slack API platform and create a Slack App.

  1. Configure the permissions of the Slack App and set the corresponding permission scopes (Scopes)
  • app_mentions:read
  • chat:write
  • im:history

  1. Install the Slack App and obtain the Token for the bot

Step 2: Create an AirCode application

  1. Quickly generate your own AirCode Node.js application using the "Deploy to AirCode" button. Note: Do not directly copy the code. If you paste the code directly, you need to manually install NPM dependencies. If you haven't logged in to AirCode, you need to log in first.

  1. Paste the bot token obtained earlier from the Slack API platform into the environment variables (Environments) of the newly created AirCode application. Fill in the Bot User OAuth Token value in SlackBotToken.

  1. After setting the environment variables (Environments), click the "Deploy" button at the top of the page to deploy the entire application and make all configurations effective.

Step 3: Configure Slack Bot events

  1. After the AirCode application is deployed successfully, select the chat.js file to call, and you can see the calling URL of the current service. Copy it and paste it into the Request URL of the corresponding App event in the Slack API platform.

  1. Add events to the Slack bot
  • app_mention
  • message.im

  1. Configure support for sending messages directly to the Slack bot

Step 4: Test the chatbot

  1. You can chat privately with the bot in the chat window, or add the bot to a group and chat by mentioning the bot. At this time, the bot can chat. Since the ChatGPT capability has not been configured yet, the bot will directly return your message, which means the bot has been configured successfully.

  1. You can view the complete request data in AirCode and use the "Mock by online requests" feature to debug the code directly with online data.

Step 5: Integrate ChatGPT capabilities

  1. Go to OpenAI's console, click "Create new secret key" to generate and copy this newly generated key, and paste it into the environment variables (Environments) of the newly created AirCode application. Paste it into the value of OpenAISecret. If you don't have an OpenAI account, you can search the web for ways to get one and prepare in advance.

  1. After clicking Deploy again to deploy the service and testing, ChatGPT's reply will be supported. Currently, ChatGPT's service is relatively slow, especially when the model version is higher and the question is more complex, the longer it takes for ChatGPT's service to return.

Problem Feedback

Further Reading