Skip to main content

Overview

The TelegrmBot API uses JWT (JSON Web Token) authentication. Before accessing protected endpoints, you must:
  1. Register a new user account
  2. Login to obtain a JWT token
  3. Include the token in the Authorization header for subsequent requests
Authentication endpoints are public and do not require a JWT token.

Register New User

curl -X POST http://localhost:8080/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "[email protected]",
    "password": "securepassword123"
  }'
Creates a new user account for accessing the admin panel.

Endpoint

POST /auth/register

Request Body

name
string
required
Full name of the user
email
string
required
User’s email address (must be unique)
password
string
required
User’s password

Response

id
string
Unique identifier for the created user (UUID format)
email
string
Email address of the registered user
name
string
Name of the registered user

Success Response (201 Created)

{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "email": "[email protected]",
  "name": "John Doe"
}

Error Responses

{
  "message": "Validation Failed",
  "details": {
    "email": "Invalid email format",
    "password": "Password must be at least 6 characters long"
  }
}
{
  "message": "User Registration Failed",
  "details": "Email already registered in the system"
}

Login User

curl -X POST http://localhost:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "securepassword123"
  }'
Authenticates a user and returns a JWT token for accessing protected endpoints.

Endpoint

POST /auth/login

Request Body

email
string
required
User’s email address
password
string
required
User’s password

Response

token
string
JWT token valid for 24 hours (86400000 milliseconds)Use this token in the Authorization header for protected endpoints:
Authorization: Bearer <token>

Success Response (200 OK)

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

Error Responses

{
  "message": "Validation Failed",
  "details": {
    "email": "Invalid email format",
    "password": "Password is required"
  }
}
{
  "message": "Authentication Failed",
  "details": "Invalid email or password"
}

Using the JWT Token

After successful login, include the JWT token in all protected endpoint requests:
curl -X GET http://localhost:8080/api/conversations \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
The JWT token expires after 24 hours. You’ll need to login again to obtain a new token.

Source Code References

  • Controller: AuthController.java:42 (register), AuthController.java:66 (login)
  • DTOs:
    • RegisterRequest.java:7 - Registration request structure
    • RegisterResponse.java:3 - Registration response structure
    • LoginRequest.java:6 - Login request structure
    • LoginResponse.java:3 - Login response structure

Next Steps

Conversations

Access conversation endpoints with your JWT token

Messages

Send messages to Telegram chats

Build docs developers (and LLMs) love