Star Service (My First Slack Bot)
- 6 Devlogs
- 5 Total hours
A Slack Bot that does the following (WIP): /ss-find [phrase] - helps you see all mentions of phrase in the whole channel.
A Slack Bot that does the following (WIP): /ss-find [phrase] - helps you see all mentions of phrase in the whole channel.
The person who reviewed my ship found out that the slash command, /ss-find didn’t work in private channels. It kept saying that you had to invite it even after you invite the bot. So:
First, I figured that since a bot can’t automatically join private channels, even after being invited, it would still throw an error that the bot is already in the channel and get stuck there. So I added an if statement to handle that scenario and basically let the bot keep going. Yet, unfortunatly this didn’t work.
Then, I added a console.log to pinpoint the exact error, and I found out that the error was method_not_supported_for_channel_type even after you invite the bot, which really dumbfounded me. Hence, I decided to ask Claude about it, and it advised to only say to invite the bot when the error ISN’T either method_not_supported_for_channel_type or already_in_channel. This helped me find out that the error is actually a missing scope, and I added the group: history scope to my bot token.
Finally, I tested /ss-find in a new channel to make sure that it said to invite the bot instead of failing. I also retested all of my slash commands in both public and private channels to be safe.
Published Slack Bot to npm as a package (I thought I should since the video before you make your first ship said to)
I faced an issue with the hosting:
The API call kept timing out.
First, I tried a few small tweaks including increasing the timeout and adding https to reuse existing connections rather than forming new connections with each new request.
But in the end, what really worked (tho I think the https helped too) was initiating the api call when the bot is started, so it can have the quote ready before you even call the command.
Finally, just in case, as a fallback, every time a sucessful api call happens, it updates an array so that in case the next api call isn’t successful, the previous successful call can be reused.
Additionally I updated my README: https://github.com/rianpatel2013-glitch/Star_Service
Finished my third and final command:
/ss-quote
This command fetches a quote from https://zenquotes.io/, and displays it with the author
I also finished hosting this project on Nest.
My Github Repository: https://github.com/rianpatel2013-glitch/Star_Service
I finished the second command for my Slack bot:
/ss-shower-thought
This command gave the user a random shower thought from a collection of 100.
This actually took me about 3 hours
First I tried https://docs.nickf.me/projects/shower%20thoughts/:
I spent about 30 mins reading it, setting it up, and trying to fix the 404 error. But eventually find out that it wasn’t my fault, but that the GitHub repo, and the link were removed.
I spent about 20 mins coding something so that all of the thoughts pulled would be shown to the user at random, and before each user sees any duplicates, they will see all of the thoughts that were fetched first.
Then I tried https://rapidapi.com/inramanlabs/api/stapi-showerthoughts:
I spent about an hour:
Making an account and setting it up
Then ensured that the API and plan are free and will stop working if it exceeds limit, rather than requiring me to spend money.
Then I found out how to actually get the api key (it wasn’t like I am accustomed to, the Studio tab misled me)
Then I found out where to cancel my subscription, just in case (I didn’t want to end up paying any money)
Then I tried to code it myself, using AI to find out how to tackle the parts I didn’t understand
Then I got a 505 error, and I thought that it might be an issue on my end cuz surely an API on a big website isn’t actually down.
So then I started experimenting on the website and found a code snippet that works for Node.js, and I got the same error again, and I tried a few ways to fix it, which didn’t work. Then I used the test method on the website itself, which didn’t work, and realized the issue was probably on their end.
Then I tried pulling directly from Reddit:
I spent about an hour:
Trying to code something to fetch from Reddit (I found the URLs and stuff, it was perfect), but I got a 403 error because Reddit doesn’t allow random bots to access it
Then I read https://developers.reddit.com/docs just to realize that it’s for making a Reddit bot rather than fetching from Reddit
Then I watched a YouTube video and realized I’ll have to make an app on https://www.reddit.com/prefs/apps but when I tried to, it told me to go to https://support.reddithelp.com/hc/en-us/articles/42728983564564-Responsible-Builder-Policy and submit a request.
But, then I found out that, even after all this complicated set up, the token would expire every hour.
Hence, I decided to drop this, but if the request gets accepted, I might code an automatic refresh cycle for the token to keep working
Finally, I spent 20 mins on copying 100 shower thoughts from Reddit.
So uh do I need to give credits to Reddit, and if yes, where?
This is my first ever devlog!
I finished the first command for the slack bot:
/ss-find [phrase]
This command helps the user find every mention of the phrase in the whole channel.
I don’t know a lot of JS, so I had to use Claude AI for some tasks (mentioned in code), like how to actually look through the whole channel, but I know how it works and implemented it myself. I do know some JS and could do some tasks myself. (I have made a website before)
I also added it to github:
https://github.com/rianpatel2013-glitch/Star_Service/
I will make it run 24x7 after I finish all 3 commands.