Skip to content

fedigiorgio/darwin-ai-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

Darwin AI Challenge

This repository contains two projects: Connector-Service and Bot-Service.

Connector-Service

Configuration

  • TELEGRAM_TOKEN: Telegram API token.
  • BOT_SERVICE_URL: URL of the Bot-Service.

For run locally

Build

npm install

npm install typescript

npx tsc

Run

node dist/app.js

Supported commands

  • /telegram-id: Returns the user's telegram_id.
  • /list-expenses: Lists the expenses made by the user.
  • Any other instruction will be assumed as an expense, which will be processed and categorized. If it's not an expense, the message will be ignored.

Bot-Service

Configuration

  • OPEN_API_API_KEY: API key for Open API.
  • DB_HOST: Database host.
  • DB_PORT: Database port.
  • DB_USER: Database username.
  • DB_PASSWORD: Database password.
  • DB_NAME: Database name.

For run locally

Install dependencies

pip install -r requirements.txt

Run

python3 src/app.py

Endpoints

  • POST /api/telegram-users/{telegram-id} Registers a user associated with the telegramId.

  • GET /api/telegram-users/{telegram-id}/expenses Lists all expenses of the user in JSON format:

  {
    "expenses": [
        {
            "added_at": "Sat, 25 May 2024 18:23:55 GMT",
            "amount": 2.0,
            "category": "FOOD",
            "description": "McDonalds"
        },
        {
            "added_at": "Mon, 27 May 2024 03:01:39 GMT",
            "amount": 60.0,
            "category": "ENTERTAINMENT",
            "description": "The Legend of Zelda Breath Of The Wild"
        }
    ]
  }
  • POST /api/telegram-users/{telegram-id}/expenses Receives JSON with a 'message' field containing the expense description, e.g., "Pizza, 20 bucks." The bot responds with the categorized expense in the following format:

Request

{
    "message": "Pizza, 20 bucks."
}

Response

{
    "added_at": "Mon, 27 May 2024 20:46:43 GMT",
    "amount": 20.0,
    "category": "FOOD",
    "description": "Pizza"
}

If the message is not an expense, it returns a bad request (400), if the user does not exists unauthorized (401).