You are browsing as a guest. Sign up (or log in) to start making projects!

Ship #1

NasaBot

This was a fun project to learn more about building Slack apps with Bolt and working with external APIs. This was my very first time writing js and my first time ever working with a bot like this. This was quite a fun experience and I am excited to potentially continue devoping this.

The bot can fetch today's Astronomy Picture of the Day, random APODs, and HD versions when available, while automatically handling both images and videos. I also cleaned up the code by creating a reusable command registration function to avoid duplication.

It was a great exercise in building something practical while getting more comfortable with Slack integrations, asynchronous API calls, and structuring a small Node.js project. Looking forward to adding features like searching by date and scheduled daily posts next.

Try project → See source code →
Open comments for this post

1h 39m 48s logged

Code cleanup

Quick summary

I refactored the NasaBot to improve code quality, readability, and maintainability by reducing duplicated code and separating common functionality into reusable functions.

Changes made

  • Configured a reusable Axios client for the NASA APOD API using a base url, api key, and request timeout
  • Created a fetchApod() function to retrieve APOD, removing duplicated API request code
  • Added formatExplanation() helper function to truncate long APOD descriptions to display in slack
  • Added a sendAPOD() function to format and send APOD responces, without repeated code
  • Better logging

Overall, after this rework, it should be much easier to add future features and maintain the bot.

0
0
7
Open comments for this post

58m 44s logged

Set up the bot and added the first few commands

1. nasabot-apod

Displays NASA's current Astronomy Picture Of the Day.

2. nasabot-random

Displays a random Astronomy Picture Of the Day.

3. nasabot-hd-apod

Displays NASA's current Astronomy Picture Of the Day in HD.

4. nasabot-hd-random

Displays a random Astronomy Picture Of the Day in hd.

5. nasabot-ping

Gets the current nasabot latency

6. nasabot-help

Shows all nasabot commands

All APOD commands display the title, date, and description nicely
formatted alongside the image. The occasional APOD YT video will be
displayed as a link.

0
0
23

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…