My first slack bot!
- 22 Devlogs
- 21 Total hours
This bot isn't slacking off, it replies to messages 24/7!
This bot isn't slacking off, it replies to messages 24/7!
I finally got it working. I discovered the error was in how the commands were being loaded, since they were all being loaded from a “commands” folder via index.js, they were taking too long to respond; because of the response time limit, an error kept popping up. I managed to fix it, though, and now it works =) I also fixed some bugs in other commands.
I created a command called /koi-help that lists all the bot’s available commands. This will be useful since we already have quite a few commands; I plan to replace that wall of text with a menu where the user can choose a category (general, animals, utilities, games), and the bot will respond with the commands for that category to avoid cluttering the chat.
Still struggling with this command (/koi-user), it was supposed to be ‘easy,’ but I just ended up complicating the code even further. Well, I’m still trying to organize the elements in the image and fix an error that prevents the bot from sending the card to the user, it’s getting really annoying (why does JS have to be like this?). I hope to finish this command soon; maybe DevLog 18 will be about that, but for now, I’ll keep working on it 🥀🙏
Fixing bugs again. I gave up on using Python + JavaScript; honestly, it was getting too difficult. Now I need to sort out the positioning, because when I was porting the code from Python to JS, the elements ended up out of place. I’m not sure if Python and JS handle image pixels differently.
I’m reviewing some commands I’ve already implemented and fixing a few issues. Strangely, the bot is taking a while to respond; it keeps displaying the message /koi-calc failed because the app did not respond... repeatedly, yet a few seconds later, the bot actually executes the command which is really odd.
Today I added two more simple commands /koi-rps and /koi-calc. /koi-calc actually already existed, but I had ended up deleting it.
/koi-rps is a small Rock, Paper, Scissors game. The user chooses rock, paper, or scissors, and Koizinho makes a random choice. Then, the bot compares the two choices and announces whether the player won, lost, or tied.
Well, I finally finished the Easy-PIL part in Python! The card is ready now.
I also set up the system so that data is automatically populated based on a JSON file. When someone uses the /koi-user command, it generates a JSON file with the selected user’s information, and then the Python script uses that data to create the card.
I designed the card myself in Canva. I spent way too much time on something so simple XD, but I really liked the result!
I’m developing a new command called /koi-user. It displays information about the user you choose.
Since the arguments of slash commands in Slack aren’t very organized (in the sense of having defined types), I had to work around the problem. In Discord, for example, you can define an argument as user_mention, so Discord itself understands that it’s a user.
In Slack, it doesn’t work that way. You can’t even pass a mention as an argument to the command, lol.
So the solution I found was to create a modal. When you use the command, a window opens with all the users in the workspace, and you can search by name or choose one from the list. After sending, the bot generates an image with some user information and sends the result to you.
(Some text is still in Portuguese because I haven’t translated everything into English yet. ;-;)
I decided to continue developing the bot, so here’s what I’ve done since the last update:
I improved the project’s organization by separating command groups into different files.
Now, each file has a specific responsibility:
/koi-duck, /koi-cat, /koi-dog, and others./koi-apod. I plan to add more commands in this category later./koi-say and /koi-tts.This has made the code much easier to maintain and allows for easier addition of new features.
One thing that really bothered me was when a command took a while to respond.
On Discord, when a bot is processing something, a “Bot is thinking…” message appears while it works. I couldn’t find an exact equivalent on Slack, so I decided to create my own system.
Now, some commands send a loading message first—for example:
🦆 Looking for a duck…
Once the command finishes, that message is updated with the final response.
This makes for a much better experience; before, it used to look like the bot had stopped working lol.
I finally managed to enable DMs for the bot!
Now you can chat directly with Koizinho in private. It can already respond to simple messages, for example:
User: Hi!
Koizinho: Hello!
I still want to improve this part. Maybe I’ll add some form of AI or a smarter conversation system in the future.
Okay… I finally finished the project’s README! 🎉
I think it turned out pretty cool; it’s not super professional yet, but I think it does a good job of showing what the bot can do. I might improve it in the future whenever I can shake off the laziness, haha.
I also realized I used Axios quite a bit in this project. Most of the new commands rely on external APIs.
There isn’t much else to add to this devlog; at least I’m happy it’s not just a bot that replies “pong” 😆
New command, wow!! 🎉🎉🎉🎉
Person: “Wait… isn’t that just /koi-say?”
Well… sort of. It’s basically an improved /koi-say.
Meet the new command: /koi-tts.
As the name suggests, TTS stands for Text to Speech. The bot takes the text you send, uses Microsoft Edge’s TTS voices to turn it into an MP3, and then sends the audio back to you. Pretty cool. =)
(I hate path😭)
Today I added a very simple command: /koi-say.
It does exactly what the name suggests: the bot repeats the message you type. Nothing spectacular, but it’s a classic, useful command for testing interactions.
If you don’t type anything, the bot replies by letting you know that text is required. The message might seem a bit blunt… but remember: it’s just a koizinho. 😭
By the way, I was thinking about how to explain the bot’s name in English. I think the closest equivalent would be something like “little koi”. In Portuguese, we use the suffix -zinho to form a diminutive that often conveys affection or cuteness. So, koizinho would be something like a “little koi” or an affectionate way to refer to the bot.
So… continuing the animal saga, I present to you: /koi-sound. 🐾
This command makes the bot send a humble animal selection menu. Then, you just pick one (there are still only a few, hahaha), and the bot replies with an .mp3 file containing the chosen animal’s sound.
The list of animals is still small, but I plan to add many more in future devlogs.
And a quick rant: I hate path. 😭 Who decided that handling file paths had to be done this way?
Today I added 4 new commands to the bot. To be honest, it wasn’t very difficult. It was basically copying the code from the first command, changing the API, and adapting it to the particularities of each one.
(Seriously… who decided that each API would return the data in a different way? 😭 I just wanted to grab a humble image.)
The new commands are:
🦆 /koi-duck — shows a picture of a random duck.
🐱 /koi-cat — shows a picture of a random cat.
🐶 /koi-dog — shows a picture of a random dog.
🦊 /koi-fox — shows a picture of a random fox.
It was a short devlog, but at least now the bot is becoming more fun.