Python AI Chatbot Hardening

Job ID: 39788102

Budget: $30 – $250 USD

I already run a beta version of a multichannel AI-chatbot. Two Python scripts (~1 500 lines each) accept messages from Telegram, WhatsApp and, via a separate hook, Instagram, forward them to ChatGPT, and return the response. A Postgres database stores logs and basic client data; all API tokens are in place, and the system is live.

What I need during the coming week is a stability and maintainability pass, with Instagram treated as the first-priority channel for tightening the API flow.

Key deliverables
• Refactor the current codebase into clear modules: parsing, ChatGPT relay, channel dispatch, logging/DB access.
• Optimise message handling so response time stays low even under load—profiling and resource trimming where needed.
• Harden external integrations, with special focus on the Instagram Business API; Telegram and WhatsApp should receive the same retry / timeout strategy once the pattern is proven.
• Add a robust error-control layer: automatic retries on transient faults, and instant admin alerts (e.g. via email or a dedicated Telegram chat) for API, database, or unhandled Python exceptions.
• Implement structured logging into Postgres, keeping current tables intact while expanding fields for error tracking and metrics.
• Full debugging sweep to eliminate edge-case crashes.
• Inline comments throughout the revised code and a concise three-page A4 markdown or PDF document explaining architecture, setup, and extension points.

Acceptance
I’ll test by hammering each channel, deliberately killing APIs and DB connections, and checking that retries and alerts fire while no message is lost. Once all tests pass, the documentation reads cleanly, and the repository is ready for the next contributor, the job is done.

Tech stack assumptions: modern Python (3.10+), async-friendly libraries such as aiohttp / requests-async, aiogram / pyrogram for Telegram, whatsapp-cloud-api wrappers, and Instagrapi or direct Graph API calls for Instagram. Feel free to propose alternatives if they improve stability.