The Core Problem

Crypto traders discover DeFi products through Telegram. They join groups, ask questions, watch signals, and eventually swap. But most projects treat every new member the same -- a welcome message, a link to the website, and silence. The first 48 hours after a trader joins a DeFi product's Telegram community are the highest-leverage engagement window. Miss it, and the trader churns to a competitor's bot that provides real-time value immediately.

DeFiKit needed a Telegram bot that could onboard crypto traders automatically, segment them by experience level and wallet activity, and deliver a personalised education-to-conversion sequence without human moderation.

The Solution: Automated Onboarding Sequences via Telegram Bot

DeFiKit's Telegram Marketing Engine is a Cloudflare Workers-based bot that manages full onboarding funnels across 14 Telegram communities. It uses D1 for state persistence, KV for rate-limiting and deduplication, and webhook-based message routing to deliver personalised sequences.

Onboarding Funnel Structure

| Step | Timing | Content | Goal |

|---|---|---|---|

| 1 | Instant | Welcome + wallet connect prompt | Establish utility |

| 2 | +5 min | Signal preview: 3 free alerts | Demonstrate value |

| 3 | +1 hour | Tutorial: first swap via bot | Reduce friction |

| 4 | +6 hours | Personalised recommendation | Drive action |

| 5 | +24 hours | Re-engagement if inactive | Prevent churn |

| 6 | +72 hours | Advanced features overview | Deepen engagement |

Each step is a self-contained Worker handler that reads the user's state from D1 and decides the next action. The entire funnel runs on webhooks -- no polling, no cron, no scheduled tasks.

Architecture: Stateful Bot Without a Server

The bot uses a conversation state pattern that fits Cloudflare Workers' stateless execution model:

```javascript

// Onboarding state machine (simplified)

const STATE = {

WELCOME_SENT: 'welcome_sent',

WALLET_CONNECTED: 'wallet_connected',

SIGNAL_PREVIEW_SENT: 'signal_preview_sent',

TUTORIAL_SENT: 'tutorial_sent',

FIRST_SWAP_COMPLETE: 'first_swap_complete',

ONBOARDED: 'onboarded',

CHURNED: 'churned'

};

async function handleMessage(userId, chatId, text, env) {

const state = await env.DB.prepare(

'SELECT current_state FROM user_onboarding WHERE user_id = ?'

).bind(userId).first();

if (!state) {

// New user -- start onboarding

await sendWelcome(chatId, env);

await env.DB.prepare(

'INSERT INTO user_onboarding VALUES (?, ?, ?, ?)'

).bind(userId, 'welcome_sent', Date.now(), 0).run();

return;

}

return advanceState(userId, chatId, state.current_state, text, env);

}

```

Each state transition is idempotent -- if the Worker times out and retries, duplicate messages are caught by KV-based deduplication with a 60-second TTL. The deduplication key is `onboard:userId:stepNumber`, and the check happens before any side effect (message send or DB write).

Segmentation Logic

The bot segments users based on two signals gathered during onboarding:

1. **Wallet age** (from connected wallet: > 6 months = experienced, < 1 month = new)

2. **Previous DEX interaction** (did they swap through DeFiKit before?)

Experienced traders skip the basic tutorial (step 3) and go straight to personalised recommendations. New traders get the full 6-step sequence with more educational content. This segmentation improved onboarding completion rate by 52% compared to the previous one-size-fits-all approach.

Content Personalisation by Segment

The message content at each step adapts based on the user's segment. A new trader's step 3 tutorial includes basic concepts like slippage and gas fees. An experienced trader's step 3 is replaced with advanced strategies like arbitrage detection or liquidity mining opportunities. The content templates are stored in KV as JSON blobs, allowing the marketing team to update them without redeploying Workers:

```json

{

"step3_tutorial": {

"beginner": "Here is how to execute your first swap...",

"experienced": "You might be interested in our cross-DEX arbitrage scanner..."

}

}

```

This templates-as-config pattern means the marketing team can A/B test message content without needing a developer deployment. They update the KV key, and the next webhook invocation picks up the change.

Results After Launch

DeFiKit deployed the Telegram Marketing Engine across 14 communities serving 8,400 unique users in the first month:

- **Completion rate:** 68% of new users completed steps 1-4 (wallet connect through first swap), up from 31% with manual onboarding

- **Time-to-first-swap:** Reduced from 72 hours (manual) to 4.2 hours (automated) -- a 17x improvement

- **Re-engagement:** Step 5 re-engagement messages recovered 23% of users who stalled after wallet connection

- **Support tickets:** Automated onboarding eliminated 340 support tickets per month related to 'how do I start using this?'

- **Scalability:** A single Worker handles all 14 communities with < 50ms p50 response time. Each community adds ~$0.35/month in D1 reads

- **Conversion revenue:** Traders who completed the automated onboarding generated 2.4x more trading volume in their first 30 days vs users who did not complete onboarding

Key Takeaways

- Telegram bots are the highest-leverage marketing channel for DeFi products -- they meet traders where they already spend their time

- A state-machine pattern on Cloudflare Workers eliminates the need for a dedicated bot server while supporting complex multi-step funnels

- Segmentation by wallet maturity dramatically improves onboarding yield: experienced traders resent beginner content, new traders need hand-holding

- Templates-as-config (KV-based content storage) decouples marketing from engineering, enabling rapid A/B testing without deployments

- Automated onboarding is not just a retention tool -- it directly correlates with revenue by reducing time-to-first-swap and increasing first-month trading volume by 2.4x