TGJU -> Telegram Channel Bot
============================

You do NOT need PHP knowledge to customize the bot.
Normally you only edit these 3 files:

1. settings.ini
   - Telegram bot token
   - Channel username / ID
   - Toman or Rial
   - Optional Telegram custom emoji IDs

2. schedule.ini
   - Choose which days and times the bot posts
   - Times use 24-hour format
   - Timezone is GMT+3:30
   - catch_up_minutes controls how long a missed scheduled time stays valid

3. message_template.txt
   - Controls exactly how the Telegram message looks
   - You can change English words, spacing, lines, HTML bold tags, links, etc.
   - Keep any {placeholder} that you still want the bot to fill automatically


MESSAGE TEMPLATE PLACEHOLDERS
=============================

Emoji:
{title_emoji}
{tether_emoji}
{gold18_emoji}
{brent_emoji}
{bitcoin_emoji}
{coin_emoji}
{clock_emoji}
{source_emoji}

Prices:
{tether_price}
{gold18_price}
{brent_price}
{bitcoin_price}
{coin_price}

Price changes:
{gold18_change}
{brent_change}
{bitcoin_change}
{coin_change}

Date and time:
{date}
{time}

You can delete any line or placeholder you do not want.
Do NOT rename a placeholder unless you also want it to stop working.

Telegram HTML supported in message_template.txt includes, for example:
<b>bold</b>
<i>italic</i>
<code>code style</code>
<a href="https://example.com/">link</a>


EXAMPLE SCHEDULE
================

sat = "09:00,12:00,15:00,18:00,21:00"
sun = "09:00,15:00,18:00"
fri = ""

An empty day means no posts that day.

CATCH-UP WINDOW
===============

The default is:

catch_up_minutes = "20"

This means a 09:00 scheduled post can still be sent if cron first runs at
09:05, 09:10, 09:15, or 09:20. Once that 09:00 slot has been sent, state.json
prevents it from being sent again. At 09:21 or later, the 09:00 slot is expired.

This works well with a cPanel cron that runs every 5 minutes.


INSTALLATION
============

1. Upload the tgju_telegram_bot folder to your hosting.
   Recommended location:
   /home/CPANEL_USERNAME/tgju_telegram_bot/

   Keeping it outside public_html protects your bot token.

2. Open settings.ini and enter:
   - bot_token
   - channel_id

3. Open schedule.ini and choose your posting times.

4. Open message_template.txt and customize the Telegram post if desired.

5. Preview the template without sending anything:

   php /home/CPANEL_USERNAME/tgju_telegram_bot/bot.php --preview

6. Test a real post immediately, ignoring the schedule:

   php /home/CPANEL_USERNAME/tgju_telegram_bot/bot.php --force

7. Recommended: add this cPanel cron job to run every 5 minutes:

   */5 * * * * /usr/local/bin/php -q /home/CPANEL_USERNAME/tgju_telegram_bot/bot.php >/dev/null 2>&1

   If your hosting uses /usr/bin/php instead:

   */5 * * * * /usr/bin/php -q /home/CPANEL_USERNAME/tgju_telegram_bot/bot.php >/dev/null 2>&1

   Running every minute is also safe if you prefer.

The cron can run every minute or every 5 minutes safely. bot.php checks schedule.ini and posts only for a due scheduled slot in GMT+3:30.
The default 20-minute catch-up window allows a missed exact minute to be sent shortly afterward.
It also keeps state.json so the same scheduled slot is not posted twice.


FILES CREATED AUTOMATICALLY
===========================

bot.log
- Error and success log.

state.json
- Remembers the most recent scheduled post to prevent duplicates.

run.lock
- Prevents two copies of the bot from running at the same time.

Do not worry if these files do not exist after upload. The bot creates them when needed.


CUSTOM / PREMIUM TELEGRAM EMOJI
===============================

Custom emoji settings are in settings.ini.

Example:
enabled = "yes"
title_id = "YOUR_CUSTOM_EMOJI_ID"
title_fallback = "📊"

If you need to discover an emoji ID, first set the bot token, send the custom emoji to the bot, and run:

php /home/CPANEL_USERNAME/tgju_telegram_bot/emoji_ids.php

If Telegram rejects a custom emoji in a channel post, the bot automatically retries with the normal fallback emojis.
