DEV Community

Prakhar Doneria
Prakhar Doneria

Posted on

How to use Sketchub Telegram Bot ?

Sketchub Telegram Bot

In this blog post, we'll delve into the usage of a Telegram bot powered by the Telegraf library, providing seamless interaction with the Sketchub API. This bot allows users to explore and retrieve information about projects and users on Sketchub, a platform for sharing creative projects.

Setting Up the Bot

The bot is initialized using the Telegraf library in Node.js. The start command welcomes users, and the /categories command fetches and displays project categories from Sketchub.

bot.start((ctx) => ctx.reply('Welcome! Use /categories to view categories.'));
bot.command('categories', async (ctx) => {
  // ... (code to fetch and display categories)
});
Enter fullscreen mode Exit fullscreen mode

Project Categories

The /categories command sends a request to the Sketchub API to retrieve project categories. It then formats and displays the categories along with the total number of projects in each.

Example Usage:

  • User: /categories
  • Bot: Displays a list of categories and project counts.

Project Details

Commands like /id and /projectList provide detailed information about a specific project or a list of projects.

bot.command('id', async (ctx) => {
  // ... (code to fetch and display project details by ID)
});

bot.command('projectList', async (ctx) => {
  // ... (code to fetch and display a list of projects)
});
Enter fullscreen mode Exit fullscreen mode

Example Usage:

  • User: /id 123
  • Bot: Displays detailed information about the project with ID 123.

Finding Users

Commands like /find and /detail allow users to search for Sketchub users and retrieve detailed user profiles.

bot.command('find', async (ctx) => {
  // ... (code to find and display user information)
});

bot.command('detail', async (ctx) => {
  // ... (code to fetch and display detailed user profile)
});
Enter fullscreen mode Exit fullscreen mode

Example Usage:

  • User: /find JohnDoe
  • Bot: Displays a list of relevant users with their IDs and names.

Handling Errors

The bot is equipped to handle errors gracefully, providing users with informative messages in case of any issues during API requests.

Example Usage:

  • User: /categories
  • Bot: Displays an error message if there's an issue with fetching categories.

Conclusion

This Sketchub Telegram bot allows users to seamlessly interact with the Sketchub platform directly from their Telegram app. Whether exploring project categories, retrieving project details, or finding user profiles, the bot provides a convenient interface for users to engage with Sketchub's creative community.

Top comments (0)