Friday, September 20, 2024
HomeWordPress DevelopmentHow you can make a Slackbot (2022 GUIDE)

How you can make a Slackbot (2022 GUIDE)


On this article I’ve principally simplified the Getting Began Information of Slack Bolt to one thing that I might had wished to be avaible after I made my very own bot. I’ve taken some code and inspiration from the Slack Bolt for javascript getting began information and documentation.

REQUIRMENTS:
Pc & Web Entry
Node put in
Slack workspace & fundamental information of slack
Fundamental programming information
Visible Studio Code (or different code editor, however VS Code shall be used as instance)
Prettier (or one thing comparable) put in to VS Code

Go to api.slack.com and click on “CREATE AN APP”
api.slack.com

Select the choice to start out “From scratch”
click the

Select a reputation to your bot and what workspace to develop your bot in
screenshot

Click on socket mode from the left panel and allow it. (Title the token one thing that you’ll keep in mind after which click on Generate)

Socket Mode

Click on slash command after which select “create new command”
create new command

Give the command identify that describes it is performance (identical applies to description and utilization trace) for our functions we’re going to create /hiya command that can make the bot say hiya.

Image

Create new folder utilizing:

 mkdir slack-app
Enter fullscreen mode

Exit fullscreen mode

Then do:

 cd slack-app
Enter fullscreen mode

Exit fullscreen mode

after which:

 npm init
Enter fullscreen mode

Exit fullscreen mode

Create index.js
Image

Set up slack-bolt for javascript utilizing:

npm set up @slack/bolt
Enter fullscreen mode

Exit fullscreen mode

After it has put in write the next into the index.js:

const { App } = require('@slack/bolt');

const app = new App({
  token: course of.env.SLACK_BOT_TOKEN,
  socketMode: true,
  signingSecret: course of.env.SLACK_SIGNING_SECRET
  appToken: course of.env.SLACK_APP_TOKEN
});
Enter fullscreen mode

Exit fullscreen mode

After that put few empty traces and the write:

app.command('/hiya', async ({ command, ack, reply }) => {
    await ack();

    await reply("Hi there, world!");
  });

Enter fullscreen mode

Exit fullscreen mode

After which few empty traces once more…. …after which write the next there:

(async () => )();
Enter fullscreen mode

Exit fullscreen mode

Now we’re carried out with virtually all of the coding. We’ll simply must create the .env file to retailer all of our Tokens and different secrets and techniques.

image

Write the next to the .env file:

SLACK_BOT_TOKEN=
SLACK_SIGNING_SECRET=
SLACK_APP_TOKEN=
Enter fullscreen mode

Exit fullscreen mode

Then return to the slack app “dashboard” and click on fundamental info from the left panel.

Basic Information

Copy the signing secret and put it after the “SLACK_SIGNING_SECRET=” within the .env file. (Additionally keep in mind to save lots of the file utilizing Ctrl + S on occasion.)

Subsequent go to the OAuth and Permissions tab on the Slack dashboard (it son the left panel there). and click on Set up to Workspace.

Install to workspace

After you’ve got put in it copy the OAuth token and paste it after the “SLACK_BOT_TOKEN=” factor.

Return to “fundamental info” tab and scroll down until you see the “App-Degree-Token” and the token you created earlier than. Click on it (the blue a part of it) and duplicate the token (by clicking “copy” button). The paste it after the “SLACK_APP_TOKEN=”.

Then kind the next to the terminal:

npm set up dotenv --save
Enter fullscreen mode

Exit fullscreen mode

then add to the highest of the code:

require('dotenv').config()
Enter fullscreen mode

Exit fullscreen mode

now you are code ought to appear to be this:

require('dotenv').config()
const { App } = require('@slack/bolt');

const app = new App({
  token: course of.env.SLACK_BOT_TOKEN,
  socketMode: true,
  signingSecret: course of.env.SLACK_SIGNING_SECRET,
  appToken: course of.env.SLACK_APP_TOKEN
});


app.command('/hiya', async ({ command, ack, reply }) => {
    await ack();

    await reply("Hi there, world!");
  });


(async () => )();
Enter fullscreen mode

Exit fullscreen mode

then kind node index.js

now go to the workspace you put in the app to.

Thanks for studying this.

Assets I used:
Slack Bolt for Javascript Documentation
Slack API Documentation

END RESULT

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments