manual hero
ENTH
PART 4 · Connecting channels

LINE and Telegram bots

LINE and Telegram via n8n

TL;DR — the 30-second summarytldr

This chapter plugs your "storefront" into the customers who already live in chat — LINE and Telegram — with one identical pattern for both: the platform sends a webhook to n8n on the NAS → the workflow calls LiteLLM (model thai-chat-rt) → it replies, and the user gets an answer within ~5–30 seconds

When to usewhen to use

Do this once the core system is ready (chapters 3–4) and you have bot accounts:

  • LINE: create a Messaging API channel at console.line.biz (the free plan is enough for answering chats) — you get a channel secret + access token
  • Telegram: talk to @BotFather, create a bot, receive a token
  • Both need a public webhook URL — use the tunnel/domain name from chapter 2

How-tohow to

The same pipeline for both platforms:

LINE / Telegram platform
  -> webhook -> n8n on the NAS (workflow)
     1. verify the signature (LINE) or token (Telegram)
     2. load the user's conversation state
     3. call LiteLLM /v1/chat/completions  model=thai-chat-rt
        (think off, num_predict 1024, timeout 51 s)
     4. format the reply (trim length, convert links, MarkdownV2 for Telegram)
     5. reply through the reply API

All secrets (secret/token) live only in the n8n credential store — never embed them in workflow JSON (a scanner checks weekly)

The UX budget we hold ourselves to: 30 seconds — anything past that counts as a failure no matter how good the answer is (in the 50-case evaluation, 2 cases hit this ceiling — those structured cases were sent to a fallback instead)

If anything gets stuck → chapter 9

Config exampleconfig example

The part you "must" get right is the model route on the LiteLLM side (from chapter 4):

- model_name: thai-chat-rt
  litellm_params:
    model: ollama_chat/qwen38-chat
    extra_body: { "think": false }   # the most important line in this chapter
    num_predict: 1024                # a ceiling sized for chat
    timeout: 51

Both bots share one route + one key each (BOM_KEY_LINE / BOM_KEY_TELEGRAM from chapter 4)

Pro tip — field-tested advicepro tip

★ PROD LESSON
The empty-answer bug — the most expensive lesson in bots — early on, the LINE bot would sometimes reply "no reply message" with no error at all — the root cause was think left on alongside a low answer ceiling: the model burned its entire budget on inner thoughts and returned an empty reply (done_reason=length) — fix the root cause with think:false on the route, not by retrying at the far end
★ PRO TIP
A separate alert bot — besides the chat-answering bots, we run one more Telegram bot (its own token) that does exactly one thing: alert when an Uptime Kuma probe changes state up or down — kept separate so urgent messages never drown in customer chat

FAQfaq

Q: A hundred people asking at once — can it cope? — yes; the model answers at ~30 tok/s and n8n manages the queue, but if the business grows to thousands of messages per minute, add the extra safety margin from chapter 9

Q: Are images/voice in chat supported? — voice-to-text (STT) works through Whisper on the i9; images use a vision model according to what the route allows

For other questions see the FAQ

See alsosee also

Figuresfigures

A sample conversation (reconstructed from real traffic, customer data masked) — you can see the reply comes back in natural Thai: direct answers, no Chinese characters mixed in:

LINE @icafefx — sample conversation (sanitized mock) · chat mock
User: Is gold worth entering today?Bot: In short — gold is pulling back; support sits above the old support, watch the major support first, and only consider the sell side if it breaks; waiting for the daily candle close is recommendedUser: Can you summarize that in 3 bullets?Bot: Sure (1) Trend: a pullback within the range (2) Point of interest: the major support (3) What to do: wait for confirmation before entering# average reply time 5-10 seconds / no Chinese characters (chapter 6 recipe)

The real conversation was re-summarized to protect customer privacy — the structure of the reply is unchanged

No real platform-side screenshots of the chat room are attached in this edition, because that would mean digging into the bot owner's accounts/sessions (our "never touch the real thing just to take a photo" policy) — the n8n workflow editor is likewise reachable only through internal SSO; to see the real thing, catch the video when it is ready (below)

Videovideo

Real screen recording for this lesson · click play to hear the summary · not investment advice

▶ Watch the manual video: https://youtu.be/O4hM39cgDCY