The #1 in Social Network Automation
5 stars based on
48 reviews
Also, the opinions expressed here are solely her own and do not express the views or opinions of my employer. My step-by-step instruction uses Node. Before building what they call App, you need this dry-run on your chat room. Sign in to your Slack account and choose your command at my. Just go ahead and fill out some of the fields. If you wish to use ngrok for your development too, bot like status picture ngrok from https: In this case, localhost: In this case, copy this URL, http: In this case the bot will answer with the description of status code with [a cat picture] https: Because you have set your ngrok to localhost: Here, you need to look for the value of textwhich comes from a user.
If a user enter a wrong value, throw some error or send a message, for example, look only for a digit:. In this example, I am using two parts in the response; 1 text and 2 attachmentswhich is an additional field displayed within the gray border, where I include an image.
Of course you can display text and change the border color in the attachment if you want. Please note that in this code sample above, I hard-code the text and image URL, but in my actual codeI keep all text strings in a separated file, and look it up if the user query matches.
If not, display an error message privately. In the next step, you will handle the authentication and deploy the code. So if you want to distribute your command bot, read on! To share your custom integration, you need to deploy the code and make it installable. To do so, you need to work on a few more things. You can fill out the rest of the form later. The App config may bot like status picture a bit confusing because there are multiple parts and you may not even notice everything first. For a slash command bot, you need to fill out at least these sections:.
Slack uses OAuth 2. The diagram shows below shows what you need to do, and I took this from the Slack API doc and modified:. But later I realized that authentication with the button! First, you need to set up a static web page. It can be a part of your node app, or bot like status picture.
I made it independently from my node app, and host it on GitHub Pages. Then go to https: Make sure to check Commands for the scope. Notice the scope- along with commandsadd team: Once you get bot like status picture temp code, you need to POST the code along with your credentials to exchange the code for an access token.
Once the auth is done, you are done. To obtain the team name as a part of the chat room URLuse team. You need to use the access token to be bot like status picture to access the API.
For this article, I simplified all my code, but check out the entire code on GitHub to see all the error handlings and when to use Verification token for your bot like status picture.
Of course, you can deploy wherever you want. But if you want to deploy to Heroku like I did, I found this article bot like status picture Heroku helpful. Make sure to set up your env vars where you set in your. Bot like status picture you see, writing a Slack slash command itself is easy, but to figuring out the whole process to make the bot available to everybody was a bit pain for me. I spent most of my time reading the docs to just figuring out, and spend far less for coding.
There are two parts. Writing a slash command with Node. Using ngrok If you wish to use ngrok for your development too, download ngrok from bot like status picture Enter a status code like !