# Testing & Production (/docs/cookbook/risex-telegram-bot/testing)



import { Steps, Step } from 'fumadocs-ui/components/steps';
import { Tabs, Tab } from 'fumadocs-ui/components/tabs';

## Running and Testing

### Start Both Apps

From the root directory:

<Tabs items={['npm', 'yarn', 'pnpm', 'bun']} groupId="package-manager">
  <Tab value="npm">
    ```bash
    npm run dev
    ```
  </Tab>

  <Tab value="yarn">
    ```bash
    yarn dev
    ```
  </Tab>

  <Tab value="pnpm">
    ```bash
    pnpm dev
    ```
  </Tab>

  <Tab value="bun">
    ```bash
    bun run dev
    ```
  </Tab>
</Tabs>

This starts:

* Telegram bot on `http://localhost:8008`
* Frontend on `http://localhost:3000`

***

### Complete Registration

<Steps>
  <Step>
    ### Get Telegram ID

    Open your Telegram bot and send `/debug`. Copy your Telegram ID from the response.
  </Step>

  <Step>
    ### Register Signer

    1. Open `http://localhost:3000` in your browser
    2. Click "Connect RISE Wallet" and approve
    3. Paste your Telegram ID
    4. Click "Register Trading Signer"
    5. Sign the permission in RISE Wallet popup
    6. Wait for confirmation (\~5-10 seconds)
  </Step>

  <Step>
    ### Test the Bot

    Go back to Telegram and try:

    * `/balance` - Should show 0 USDC
    * `/deposit` - Should credit 1000 testnet USDC
    * `/balance` - Should now show 1000 USDC
  </Step>

  <Step>
    ### Place Your First Trade

    Send: `buy 0.02 BTC`

    The bot should respond with order confirmation and transaction hash.
  </Step>
</Steps>

A successful trade message should look like this:

<img alt="RISEx Bot Trade Response" src={__img0} placeholder="blur" />

***

### Testing Natural Language

Try these examples:

```
✅ "check my balance"         → Shows USDC balance
✅ "show positions"           → Lists open perp positions
✅ "buy 0.02 BTC"            → Places market long order
✅ "short 0.01 ETH at 3400"  → Places limit short order
✅ "deposit 500"             → Adds 500 USDC to account
✅ "go long with 1000 USDC"  → Calculates size from USDC amount
```

The LLM will parse these into structured tool calls and execute them via the RISEx API.

***

## Understanding the Flow

Let's trace what happens when you send "buy 0.02 BTC":

1. **Message Received**: Telegram bot receives your text message
2. **Verification**: Bot checks if your Telegram ID is linked to a wallet and has a registered signer
3. **LLM Processing**: Message is sent to GPT-4o-mini with system prompt and tool definitions
4. **Intent Parsing**: LLM returns:
   ```json
   {
     "tool": "place_order",
     "params": {
       "market": "BTC",
       "side": "long",
       "size": "0.02",
       "orderType": "market"
     }
   }
   ```
5. **Key Retrieval**: Backend loads your encrypted signer key and decrypts it
6. **Signature Generation**: Backend signs an EIP-712 `VerifySignature` message using the signer key
7. **API Call**: Backend calls `POST /v1/orders/place` with the signature
8. **On-Chain Verification**: RISEx smart contract verifies the signature matches the registered signer
9. **Order Execution**: RISEx executes the perpetual futures trade
10. **Confirmation**: Bot replies with order ID and transaction hash

This entire flow completes in under 5 seconds, providing near-instant trading from natural language commands.

***

## Next Steps

You've built a fully functional AI-powered trading bot! Here are some ideas to extend it:

* **Advanced Orders**: Add stop-loss, take-profit, and trailing stops
* **Portfolio Analytics**: Track PnL over time with charts
* **Price Alerts**: Notify users when markets hit target prices
* **Multi-User Support**: Allow multiple users per bot instance
* **Risk Management**: Add position sizing calculators and risk limits
* **Market Data**: Integrate realtime price feeds and order book data

### Related Tutorials

* [RISE Wallet Demo](/docs/cookbook/rise-wallet-quickstart) - Learn more about session keys
* [Shred Ninja](/docs/cookbook/shred-ninja) - Realtime event monitoring
* [Reaction Time Game](/docs/cookbook/reaction-time-game) - 3ms transaction confirmations

### Resources

* [GitHub Repository](https://github.com/awesamarth/risex-tg-bot) - Complete source code
* [RISEx Documentation](/docs/risex) - Complete trading platform guide
* [RISEx API Reference](/docs/risex/api) - REST API endpoints
* [Telegraf Documentation](https://telegraf.js.org) - Telegram bot framework
* [OpenRouter Documentation](https://openrouter.ai/docs) - LLM integration guide
* [Viem Documentation](https://viem.sh) - Ethereum library reference

Now go build something amazing with RISEx on RISE! 🚀
