Sign inSign up

schogini/voiceflow-token-logger

By schogini

Updated almost 2 years ago

FastAPI server that logs data and generates unique tokens associated with user-provided information.

Image
0

551

schogini/voiceflow-token-logger repository overview

Schogini Voiceflow Token Logger and Generator

This Docker image provides a FastAPI server that logs data and generates unique tokens associated with user-provided information. It also includes endpoints for querying the logs and tokens in both JSON and HTML formats. The image is built using Python and FastAPI, and it requires an API key for authorization.

Features

  • Log incoming data with email and message, and timestamp in a log.txt file.
  • Generate a unique token (4-digit alphanumeric) and store it with the user’s email and message in tokens.txt.
  • Query tokens and logs:
    • Retrieve token information by token or email.
    • Display logs and tokens in a tabular view.
  • Authorization: Requires an API key for all endpoints.

Prerequisites

  • Docker installed on your machine.
  • API key stored in a .env file or passed as an environment variable during Docker run.

Endpoints

  • POST /log: Logs incoming JSON data (email, message) into log.txt with timestamp.
  • POST /token-new: Generates a new 4-digit alphanumeric token and stores it with the associated data in tokens.txt.
  • GET /token-query: Queries a token and returns its associated data.
  • GET /token-email: Returns the most recent token for a given email.
  • GET /tokens: Displays all tokens in an HTML table.
  • GET /logs: Displays all logs in an HTML table.
  • GET /help: Returns usage instructions for the available endpoints.

How to Use

1. Build the Docker Image

Clone the repository or ensure you have all the files (Dockerfile, main.py, requirements.txt) and run the following command to build the image:

docker build -t schogini/fastapi-token-logger .
2. Run the Docker Container

To run the container, you need to pass the API key via an environment variable. The server will start on port 8000.

docker run --rm -e API_KEY="your-api-key" -p 8000:8000 schogini/fastapi-token-logger

Replace "your-api-key" with your actual API key.

3. API Documentation and Usage

Once the container is running, you can access the API documentation at:

http://localhost:8000/docs

This provides interactive documentation for all available endpoints.

Example Usage
1. Log Data (POST /log)
curl -X POST "http://localhost:8000/log" \
    -H "x-api-key: your-api-key" \
    -H "Content-Type: application/json" \
    -d '{"email": "[email protected]", "message": "Test log message"}'
2. Generate New Token (POST /token-new)
curl -X POST "http://localhost:8000/token-new" \
    -H "x-api-key: your-api-key" \
    -H "Content-Type: application/json" \
    -d '{"email": "[email protected]", "message": "Generate token"}'
3. Query Token (GET /token-query)
curl -X GET "http://localhost:8000/token-query?token=1234" \
    -H "x-api-key: your-api-key"
4. Get Tokens in HTML Table (GET /tokens)
curl -X GET "http://localhost:8000/tokens?api_key=your-api-key"
5. Get Logs in HTML Table (GET /logs)
curl -X GET "http://localhost:8000/logs?api_key=your-api-key"
Environment Variables
  • API_KEY: The API key required for authentication to use the FastAPI server. You can provide it through an .env file or pass it as an environment variable when running the Docker container.
Running in Development

If you want to run the FastAPI server locally without Docker, you can set up a Python environment and install the dependencies from requirements.txt:

pip install -r requirements.txt

Then, you can run the FastAPI server with Uvicorn:

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Docker Hub

You can pull the pre-built image from Docker Hub using:

docker pull schogini/fastapi-token-logger

License

This project is licensed under the MIT License.

Company Information

This Docker image was created by Schogini Systems Private Limited. We specialize in AI Chatbot and Automation solutions for small businesses.

For more information about our services, visit: https://www.schogini.com.

Tag summary

Content type

Image

Digest

sha256:bf89c6a1d

Size

51.3 MB

Last updated

almost 2 years ago

docker pull schogini/voiceflow-token-logger