write a readme for github.

code: import telebot
import json
import os
from config import BOT_TOKEN, ADMIN_ID, LOGGING_LEVEL

bot = telebot.TeleBot(BOT_TOKEN)
user_states = {}

GAME_DATA_FILE = 'texts.json'

if os.path.exists(GAME_DATA_FILE):
    with open(GAME_DATA_FILE, 'r', encoding='utf-8') as f:
        game_data = json.load(f)
else:
    print(f"Error: '{GAME_DATA_FILE}' not found.")
    exit(1)

def log_message(message_type, user_id, username, content=''):
    if LOGGING_LEVEL == 0:
        return
    if LOGGING_LEVEL == 1 and message_type not in ['start', 'end']:
        return
    log_text = f"{message_type.upper()} - User ID: {user_id}, Username: {username}"
    if content:
        log_text += f", Content: {content}"
    bot.send_message(ADMIN_ID, log_text)

# Start command handler
@bot.message_handler(commands=['start'])
def start_message(message):
    user_states[message.chat.id] = 'start'
    send_message_with_buttons(message.chat.id, 'start')
    log_message('start', message.chat.id, message.from_user.username)

# Message handler for button clicks and text inputs
@bot.message_handler(func=lambda message: True)
def handle_message(message):
    chat_id = message.chat.id
    state = user_states.get(chat_id, 'start')
    user_input = message.text.strip()
    log_message('input', chat_id, message.from_user.username, user_input)

    if state in game_data and user_input in game_data[state]['buttons']:
        next_state = game_data[state]['buttons'][user_input]
        user_states[chat_id] = next_state
        send_message_with_buttons(chat_id, next_state)
    else:
        bot.send_message(chat_id, "I don't understand that choice. Please select one of the available options.")

# Function to send messages with keyboard buttons
def send_message_with_buttons(chat_id, state):
    if state in game_data:
        text = game_data[state]['text']
        buttons = game_data[state].get('buttons', None)

        if buttons:
            keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
            for button_text in buttons:
                keyboard.add(telebot.types.KeyboardButton(button_text))
            bot.send_message(chat_id, text, reply_markup=keyboard)
        else:
            # If no buttons, remove the keyboard
            bot.send_message(chat_id, text, reply_markup=telebot.types.ReplyKeyboardRemove())
    else:
        bot.send_message(chat_id, "Oops, something went wrong...", reply_markup=telebot.types.ReplyKeyboardRemove())

# Restart command handler
@bot.message_handler(commands=['restart'])
def restart_game_command(message):
    user_states[message.chat.id] = 'start'
    send_message_with_buttons(message.chat.id, 'start')
    log_message('restart', message.chat.id, message.from_user.username)

# Back command handler
@bot.message_handler(commands=['back'])
def go_back(message):
    chat_id = message.chat.id
    state_history = get_user_state_history(chat_id)

    if len(state_history) > 1:
        # Remove the last state to go back
        state_history.pop()
        # Update the user's current state
        user_states[chat_id] = state_history[-1]
        send_message_with_buttons(chat_id, state_history[-1])
    else:
        bot.send_message(chat_id, "You're already at the beginning of the game!")

# Function to get the user's state history
def get_user_state_history(chat_id):
    if chat_id not in user_states:
        user_states[chat_id] = 'start'
    # For simplicity, we're using a list to track state history per user
    # In a production environment, consider a more robust method or database
    if '_history' not in user_states:
        user_states['_history'] = {}
    if chat_id not in user_states['_history']:
        user_states['_history'][chat_id] = ['start']
    return user_states['_history'][chat_id]

# Overriding send_message_with_buttons to update state history
def send_message_with_buttons(chat_id, state):
    if state in game_data:
        # Update user's state history
        state_history = get_user_state_history(chat_id)
        state_history.append(state)
        user_states['_history'][chat_id] = state_history

        text = game_data[state]['text']
        buttons = game_data[state].get('buttons', None)

        if buttons:
            keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
            for button_text in buttons:
                keyboard.add(telebot.types.KeyboardButton(button_text))
            bot.send_message(chat_id, text, reply_markup=keyboard)
        else:
            # If no buttons, remove the keyboard
            bot.send_message(chat_id, text, reply_markup=telebot.types.ReplyKeyboardRemove())
    else:
        bot.send_message(chat_id, "Oops, something went wrong...", reply_markup=telebot.types.ReplyKeyboardRemove())

bot.set_my_commands([
    telebot.types.BotCommand('start', 'Start the game'),
    telebot.types.BotCommand('restart', 'Restart the game'),
    telebot.types.BotCommand('back', 'Go back one step')
])

# Handler for stopping the bot gracefully (e.g., /stop command)
@bot.message_handler(commands=['stop'])
def stop_bot(message):
    log_message('end', message.chat.id, message.from_user.username)
    bot.send_message(message.chat.id, "Thank you for playing! Goodbye.")
    # Perform any cleanup here if necessary

bot.polling()

draft: Telegram Text Adventure Game Bot
Python
Telegram Bot API
License

A simple Telegram bot that demonstrates a text-based adventure game. Players make choices by clicking on buttons, leading them through different story paths.

Features
Interactive demo game with multiple steps
Simple text-based storytelling
Users can restart the game at any time
Ability to go back one step in the story
Easily customizable story through a JSON file
Setup and Installation
Prerequisites
Python 3.6 or higher
A Telegram account
A Telegram bot token from BotFather
Installation Steps
Clone the Repository

git clone https://github.com/yourusername/telegram-text-adventure-bot.git
cd telegram-text-adventure-bot
Create a Virtual Environment It's recommended to use a virtual environment to manage dependencies:

python3 -m venv venv
source venv/bin/activate  # On Windows use venv\Scripts\activate
Install Dependencies Install the required packages using pip:

pip install -r requirements.txt
Configure the Bot Replace 'YOUR_BOT_TOKEN' in bot.py with your actual bot token:

BOT_TOKEN = 'YOUR_ACTUAL_BOT_TOKEN'
Run the Bot Start the bot by running:

python bot.py
Interact with the Bot Open Telegram, find your bot by its username, and start a conversation. Use /start to begin the game.
Usage
/start - Begin the game
/restart - Restart the game from the beginning
/back - Go back one step in the story
Customization
Editing the Story
The game story is stored in game_data.json. You can modify this file to create your own story. The structure is as follows:


"state_name": {
  "text": "The text shown to the user at this state.",
  "buttons": {
    "Button Label": "next_state_name"
  }
}
state_name: A unique identifier for each state in the game.
text: The narrative text displayed to the player at this state.
buttons: A dictionary of buttons and the states they lead to.
Adding New States
To add new parts to the story:

Define a new state in game_data.json with its text and buttons.
Reference the new state in the buttons of an existing state.
Multi-language Support
To support multiple languages:

Create separate JSON files for each language (e.g., game_data_en.json, game_data_es.json).
Load the appropriate file based on user preference or locale.
Additional Improvements
Here are some ideas for enhancing the bot:

State Persistence: Save user states to a database to maintain history even if the bot restarts.
Inline Keyboards: Use inline keyboards for a more polished user interface.
Dynamic Content: Allow users to input text, making the game more interactive.
Error Logging: Implement logging to track errors and user interactions.
Unit Testing: Add tests to ensure the bot functions correctly.