8000 GitHub - metsko/colli_parser: Repo for parsing Colruyt invoices using LLMs
[go: up one dir, main page]

Skip to content

metsko/colli_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot Webhook Setup

This guide explains how to set up a webhook for your Telegram bot to handle PDF files and process them using a Flask application.

Prerequisites

  • Python 3.6 or higher
  • pip package manager
  • ngrok for exposing your local server to the internet
  • Telegram bot token from BotFather
  • API token for securing the endpoint

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/colli_parser.git
    cd colli_parser
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables: Create a .env file in the project root with:

    TELEGRAM_TOKEN=your_telegram_bot_token
    API_TOKEN=your_api_token
    CHATGPT_API_TOKEN=your_chatgpt_api_token
    

Running the Application

  1. Start ngrok:

    ngrok http 7071

    Copy the HTTPS URL provided by ngrok (e.g., https://xxxx-xx-xx-xxx-xx.ngrok.io)

  2. Set up the webhook: Replace YOUR_NGROK_URL and YOUR_API_TOKEN with your values:

    source webhook/.env && curl -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/setWebhook" \
     -H "Content-Type: application/json" \
     -d '{"url": "'${NGROK_URL}'/webhook?code='${FUNCTION_KEY}'", "secret_token": "'${API_TOKEN}'"}'

    Local Setup Note: Remove authentication (i.e., ?code=function_key) when configuring the webhook locally.

    source webhook/.env && curl -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/setWebhook" \
     -H "Content-Type: application/json" \
     -d '{"url": "'${NGROK_URL}'/webhook", "secret_token": "'${API_TOKEN}'"}'
  3. Start the Flask application:

    python app.py

Usage

  1. Start a chat with your Telegram bot
  2. Send a PDF invoice file to the bot
  3. The bot will process the invoice and return extracted information

Security Notes

  • Keep your .env file secure and never commit it to version control
  • Regularly rotate your API tokens
  • The webhook endpoint is protected with the API token

Project Structure

colli_parser/
├── app.py              # Main Flask application
├── api_client.py       # ChatGPT API client
├── invoice_parser.py   # PDF parsing logic
├── utils.py           # Utility functions
├── config.py          # Configuration
├── data/              # PDF storage
└── .env               # Environment variables

Debugging Locally in VS Code

Open the webhook folder in VS Code and launch the debugger.

Running in Azure

  1. az login
  2. az deployment group create --resource-group colli_parser --template-file infra/azure.bicep --parameters infra/colliparser_params.bicep.bicepparam
  3. func azure functionapp publish colli-parser-func

About

Repo for parsing Colruyt invoices using LLMs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0