Step 22: Now go to “OAuths and Permission” and scroll down to “Scopes” there you will see that a scope name “channels: history” is added, if not then add it to the “Scopes”. Step 21: After that scroll down and go to the “Subscribe to bot events” then go to “Add Bot User Events” and then add a message. Now we need to again go to the Slack Developer Console, then go to Event Subscription and paste Ngrok URL with the endpoint that we define in the code. Now we will need NGROK for running that program and get the public IP address by running the code “ngrok http 5000” on NGROK and then we will get a public IP address. Step 20: Now we need to run this code and we will notice that now we will have a webserver running on. Slack_event_adapter = SlackEventAdapter(SIGNING_SECRET, '/slack/events', app) Step 19: Now after adding Signing Secret to our code we need to pass it to the slack event adapter. In that go to “Basic Information” in the left panel, then scroll down to “Signing Secret” copy it, and add it to the code. Step 18: Now again go to the Slack Developer Console. The channel name and channel=’#justtest’ string should be matched otherwise, it will not work. import slackįrom slackeventsapi import SlackEventAdapterĬlient.chat_postMessage(channel='#justtest',text='Hello World!') Step 17: Now just create a simple flask app like shown below. Step 15: Now we will see how we can respond to the “Hi” message from the user with a “Hello” message from the bot.įirst off, all go to the Slack Developer Console in that go to “Event subscriptions” and Enable Events. import slackĬlient = slack.WebClient(token=SLACK_TOKEN)Ĭlient.chat_postMessage(channel='#justtest',text='Hello') Also, we will discuss how to create a channel in the next step. Using this code we can send a “Hello” message to our “#test” channel. Step 14: Now import the slack module and follow the code shown in the image below. Step 13: Now Add your app to the channel by just typing “/invite (use the app name that you want to connect with the channel) in channel chat. Step 12: Now type your channel name and click on the “Create” Button. To open your slack account go to the channel bar and click on the “+” sign. Step 11: Now we create the channel in slack and add our app to it. Step 10: Now we install slack client python packages using pip install slackclient in our virtual environment. Step 9: Now create a python file (bot.py) and copy the above “OAuth Token” and paste it into the. Step 8: Now click on “Install to Workspace” and press on “Allow” to generate an OAuth token. Then click on the “Add an OAuth Scopes” Button under “Bot Token Scopes” and add “chat: write” as shown in the below image. Step 7: After clicking on the “Review Scope to Add” button, scroll down and find the Scope section. Step 6: Click on the “App Home” button and click on “Review Scopes to Add”. Step 5: Now give your app name and select workspace then click on the “Create App” button. Here we learn how we can get different types of responses from the bot such as: Here we will also learn how we can get customized responses from the bot such as buttons and polls. In addition to that, we will also learn how to save the file sent by the user in the channel to the bot on the server-side. Here in this tutorial, we will learn how we can create a bot in slack and add it to our channel and get the text response from the bot, and further how we can get an image, video, audio, or file through the bot. Slackbot is helpful for creating automatic messages for many purposes. Slack is a useful tool for remote teams to interact more quickly and keep documents in one location.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |