/life-chat-backend

Backend for Life Chat - platform helping psychologists to work with their patients throw chat messengers

Primary LanguageJavaScript

Life Chat Backend

Backend application for Life Chat - platform helping psychologists to work with their patients throw chat messengers.

Technologies

  • Node
  • Koa
  • Joi
  • MongoDB
  • Telegram Bot API

How to run app

  1. Set environment variables or use .env file. Example:
    DB_URI=mongodb://127.0.0.1:27017/lifechatdb
    JWT_SECRET=84573695730af7da3ab1bb716f745df7
    NODE_ENV=production
    PORT=8000
    API_VERSION=1
    
  2. Install npm dependencies:
    npm install
  3. Run the app:
    npm start

Related repositories

life-chat-ui

Available Endpoints

Users

POST /users

Creates a new user

Payload
{
  "first_name": string,
  "last_name": string,
  "patronymic": string,
  "inn": string,
  "phone": string,
  "email": string,
  "nationality": string
}
Response
{
  "id": string,
  "created_at": string,
  "first_name": string,
  "last_name": string,
  "patronymic": string,
  "inn": string,
  "phone": string,
  "email": string,
  "nationality": string,
  "experience": string,
  "rate": string,
  "welcome_message": string
}

POST /users/authorise

Authenticates a user based on credentials

Payload
{
  "username": string
  "password": string
}
Response
{
  "auth_token": string // JWT token
}

PUT /users/bot

Updates user's Telegram bot configuration parameters

Payload
{
  "token": string // User's Telegram bot token
}
Response
{
  "result": "SUCCESS"
}

PUT /users/details

Updates user details

Payload
{
  "rate": number, // Hourly pay rate in local currency
  "experience": number, // Years of experience
  "welcome_message": string // First consultation message content to be sent to patients
}
Response
{
  "result": "SUCCESS"
}

PUT /users/payment

Updates user payment parameters

Payload
{
  "card_number": string // User's bank card number, to which payments will be sent from patients
}
Response
{
  "result": "SUCCESS"
}

GET /users/me

Fetches authenticated user parameters

Response
{
  "id": string,
  "created_at": string,
  "first_name": string,
  "last_name": string,
  "patronymic": string,
  "inn": string,
  "phone": string,
  "email": string,
  "nationality": string,
  "experience": string,
  "rate": string,
  "welcome_message": string
}

GET /users/me/consultations

Fetches authenticated user's consultations

Response
{
  "id": string,
  "created_at": string,
  "status": string,
  "duration": number,
  "total_cost": number,
  "can_send_message": boolean,
  "scheduled_on": string
}[]

Consultations

GET /consultations/:consultationId

Fetches consultation by ID

Response
{
  "id": string,
  "created_at": string,
  "status": string,
  "duration": number,
  "total_cost": number,
  "can_send_message": boolean,
  "scheduled_on": string
}

GET /consultations/:consultationId/messages

Fetch messages by consultation ID

Response
{
  "id": string,
  "text": string,
  "sent_at": string,
  "patient": Patient
}[]

POST /consultations/:consultationId/reply

Sends message to the open consultation Telegram chat

Payload
{
  "text": string
}
Response
{
  "id": string,
  "text": string,
  "sent_at": string,
  "patient": Patient
}

PUT /consultations/:consultationId/start

Launches the consultation flow. Changes status of consultation from NEW to PENDING.

Response
{
  "result": "SUCCESS",
  "status": "PENDING"
}

PUT /consultations/:consultationId/prepaid

Marks consultation as prepaid. Changes status of consultation from PENDING to PREPAID.

Response
{
  "result": "SUCCESS",
  "status": "PREPAID"
}

PUT /consultations/:consultationId/complete

Completes the consultation. Changes consultation status to WAIT_PAYMENT.

Response
{
  "result": "SUCCESS",
  "status": "WAIT_PAYMENT"
}