# Telegram Bot

<figure><img src="https://2248495392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl8fxy9QV4yxlDCej4RdL%2Fuploads%2Fgit-blob-e4f6f92f6a077c0f034b182405fed204ef7ac611%2FTelegram%20Bot.png?alt=media" alt=""><figcaption><p>The Telegram Bot panel in Settings — paste your BotFather token and authorized user IDs, then toggle which event types notify you.</p></figcaption></figure>

RestocksAIO includes a Telegram bot integration that allows you to receive notifications and interact with your instance through Telegram commands.

## Getting Started

### Step 1: Create a Telegram Bot

1. Open Telegram and search for **@BotFather**
2. Start a conversation with BotFather and send `/newbot`
3. Follow the prompts to choose a name and username for your bot
4. BotFather will provide you with a **bot token** (e.g., `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`)
5. **Save this token** - you'll need it in the next step

### Step 2: Get Your Telegram User ID

1. Search for **@userinfobot** on Telegram
2. Start a conversation with @userinfobot
3. The bot will immediately reply with your **User ID** (a numeric value like `123456789`)
4. **Save this User ID** - you'll need it to authorize yourself

{% hint style="warning" %}
You must add your User ID to the authorized list, otherwise the bot will ignore your messages for security reasons.
{% endhint %}

### Step 3: Configure in RestocksAIO

1. Open RestocksAIO and navigate to **Settings**
2. Click on **Telegram Bot** in the settings sidebar
3. Enter your **Bot Token** in the "Bot Token" field
4. Enter your **User ID** (or multiple IDs separated by commas) in the "Authorized User ID(s)" field
5. Configure notification preferences:
   * **Send Telegram notifications for Bricker Mode sales**: Enable to receive sale notifications
   * **Send Telegram notifications for new offers**: Enable to receive offer detection notifications
   * **Send generated labels to Telegram**: Enable to receive shipping labels as PDF attachments when labels are generated
   * **Send Telegram notifications for application errors**: Enable to forward application errors to Telegram (disabled by default)
6. Click **Save** to save your settings
7. Click **Test Bot** to verify the connection

{% hint style="success" %}
If the test is successful, you'll receive a confirmation message in Telegram. The bot is now ready to use!
{% endhint %}

## Available Commands

Once configured, you can interact with your RestocksAIO instance using these commands:

### `/help`

Shows a list of all available commands.

**Example:**

```
/help
```

**Response:**

```
Available commands:

/info - Instance information
/notifications - Notification toggles
/notify_bricker_sales - Toggle Bricker Mode sales notifications
/notify_offers - Toggle offer detection notifications
/bricker_stats - Bricker stats snapshot
/bricker_start_all - Start all Bricker tasks
/bricker_stop_all - Stop all Bricker tasks
/help - Show this help message
```

### `/info`

Retrieves detailed information about your RestocksAIO instance, including:

* **License Key**: Your current license key
* **Subscription**: Your subscription type (Trial, Standard, Premium, or Lifetime)
* **Server Connection**: Whether the instance is connected to the RestocksAIO server
* **Database Status**: Status of the database connection
* **Last Sync**: Time since last synchronization

**Example:**

```
/info
```

**Response:**

```
📊 RestocksAIO Instance Information

🔑 License Key: ABC123XYZ789
💳 Subscription: Premium
🌐 Server Connection: ✅ Connected
💾 Database Status: ✅ Online
🔄 Last Sync: Sync: Just now
```

### `/notifications`

Shows the current notification settings for your RestocksAIO instance with interactive buttons to toggle each setting:

* **Bricker Mode Sales**: Whether notifications for Bricker Mode sales are enabled or disabled
* **Offer Detections**: Whether notifications for offer detections are enabled or disabled
* **Label Notifications**: Whether generated shipping labels are sent as PDF attachments
* **Error Forwarding**: Whether application errors are forwarded to Telegram (disabled by default)

**Example:**

```
/notifications
```

**Response:**

```
🔔 Notification Settings

Bricker Mode Sales: ✅ Enabled
Offer Detections: ✅ Enabled
Error Forwarding: ❌ Disabled

Tap a button to change the setting.
```

The response includes **On/Off buttons** for each notification type. Simply tap the button to toggle the setting - no need to type commands!

{% hint style="info" %}
Notification settings are saved immediately when you tap a button. The bot will confirm your change with a message like "✅ Bricker Mode sales notifications enabled."
{% endhint %}

### `/notify_bricker_sales`

Shows the current status of Bricker Mode sales notifications with interactive **On/Off buttons** to toggle the setting. When enabled, you'll receive notifications whenever a sale is made through Bricker Mode.

**Example:**

```
/notify_bricker_sales
```

**Response:**

```
Bricker Mode sales notifications are currently ✅ On.
```

The response includes **On/Off buttons** - tap the button to change the setting.

### `/notify_offers`

Shows the current status of offer detection notifications with interactive **On/Off buttons** to toggle the setting. When enabled, you'll receive notifications when offers are detected on your listings.

**Example:**

```
/notify_offers
```

**Response:**

```
Offer detection notifications are currently ✅ On.
```

The response includes **On/Off buttons** - tap the button to change the setting.

{% hint style="info" %}
Notification settings are saved immediately when you tap a button and will apply to all future notifications. You can check your current settings at any time using `/notifications`.
{% endhint %}

### `/bricker_stats`

Retrieves comprehensive statistics about your Bricker Mode tasks, including:

* **Controllers**: Running, stopped, and total controller counts
* **Tasks**: Running, stopped, sold, and error task counts
* **Session Sales**: Total sales during the current session
* **Session Errors**: Total errors encountered
* **Queue**: Items currently in queue
* **Lowest Ask**: Items with lowest ask vs. not lowest ask
* **Price Changes**: Price changes in the last 24 hours

The response includes **Start All** and **Stop All** buttons for quick control.

**Example:**

```
/bricker_stats
```

**Response:**

```
📈 Bricker Mode Stats

Controllers: 5 running / 2 stopped / 7 total
Tasks: 12 running / 3 stopped / 8 sold / 1 errors

Session Sales: 8
Session Errors: 1
Queue: 5
Lowest Ask: 10 | Not Lowest: 5
Price Changes (24h): 15
```

### `/bricker_start_all`

Starts all Bricker Mode tasks. This command will initiate all stopped tasks across all controllers.

**Example:**

```
/bricker_start_all
```

**Response:**

```
▶️ Started all Bricker tasks.
```

### `/bricker_stop_all`

Stops all Bricker Mode tasks. This command will halt all running tasks across all controllers.

**Example:**

```
/bricker_stop_all
```

**Response:**

```
⏹ Stopped all Bricker tasks.
```

{% hint style="info" %}
You can also use the **Start All** and **Stop All** buttons that appear when you run `/bricker_stats` for quick access to these controls.
{% endhint %}

## Notification Features

### Bricker Mode Sales Notifications

When enabled, you'll receive rich notifications whenever a sale is made through Bricker Mode, including:

* Product name and image
* Site where the sale occurred
* Style code (SKU)
* Size
* **Category** (`Resale`, `Direct`, or `Consign`) — tells you which bricker bucket the sale came from
* Store price and payout information
* Order ID
* Sale timestamp

### Offer Detection Notifications

When enabled, you'll receive notifications when offers are detected on your listings, including:

* Product name and image
* Site where the offer was made
* Style code (SKU)
* Size
* Offer amount and payout
* Profit if accepted
* **Accept Offer button** - Tap to accept the offer directly from Telegram

### Label Notifications

When enabled, you'll receive generated shipping labels as PDF attachments directly in Telegram whenever a label is created, including:

* Site where the label was generated
* File name
* The label file as a PDF attachment

This is useful for quickly accessing your labels from your phone without needing to open the application or navigate to the labels folder.

### Error Forwarding

When enabled (disabled by default), application errors will be automatically forwarded to Telegram, including:

* Error type and function
* Alert level (Warning or Important)
* Error description
* Solution description (if available)
* Stack trace (truncated if too long)

{% hint style="warning" %}
Error forwarding is disabled by default to prevent notification spam. Enable it only if you want to monitor application errors remotely.
{% endhint %}

## Multiple User IDs

You can authorize multiple Telegram users to interact with your bot by entering multiple User IDs separated by commas:

**Example:**

```
123456789,987654321,555666777
```

Each authorized user will be able to use all bot commands and receive notifications.

## Troubleshooting

### Bot Not Responding

* **Check your Bot Token**: Make sure you copied the complete token from BotFather
* **Verify User ID**: Ensure your User ID is correctly entered in the authorized list
* **Test Connection**: Use the "Test Bot" button in settings to verify connectivity
* **Check Bot Status**: Make sure the bot is running (it should start automatically when you save valid settings)

### "Unauthorized" Messages

If you receive no response from the bot, it means your User ID is not in the authorized list:

1. Double-check your User ID using @userinfobot
2. Ensure the User ID is correctly entered in settings (no extra spaces)
3. Save settings and test again

### Connection Errors

If you see connection errors:

* Verify your internet connection
* Check that Telegram is accessible from your network
* Ensure the bot token is valid and hasn't been revoked
* Try stopping and restarting the bot using the Test button

## Security Notes

* **Keep your Bot Token secret**: Never share your bot token publicly
* **Authorized Users Only**: Only users whose IDs are in the authorized list can interact with your bot
* **Regular Updates**: Keep RestocksAIO updated to receive the latest security improvements

## Next Steps

Once your Telegram bot is configured, you can:

* Monitor your instance status remotely using `/info`
* Receive real-time notifications for sales, offers, and errors
* Control Bricker Mode tasks remotely using `/bricker_stats`, `/bricker_start_all`, and `/bricker_stop_all`
* Toggle notification settings easily using interactive buttons
* Accept offers directly from Telegram notifications
* Interact with your RestocksAIO instance from anywhere
