Typestate
Sign in

FAQ bot on Telegram

Customers write to your Telegram bot. It sends the answer you saved, and a question it cannot answer waits for you.

For a shop or venue that answers the same questions every day.

Telegram logo TelegramAnthropic logo Anthropic
Start it with your agentStarting from a blueprint does not count against the action changes of your plan.

Start the FAQ bot on Telegram blueprint on Typestate

Started FAQ bot on Telegram: 2 record types, 3 web endpoints.

4 actions are compiling.

Deployed to Sandbox. Try it at your Sandbox address.

What your agent does when you start this blueprint

What runs

Each step has 3 parts: who starts it, how it reaches your backend, and the action that answers.

  1. Yousave the questions customers ask, with your replies
    Web endpoint, your keyPOST /answers
    Add an AnswerSaves the question and its reply.saves an Answer
  2. A customerwrites to your bot on Telegram, and gets the saved reply
    Telegram eventmessage
    Answer a MessageSends the reply that fits, or tells the customer a person will answer.saves a Questionsends 1 Telegram message
  3. Youread the questions the bot could not answer
    Web endpoint, your keyGET /questions
    List Open QuestionsAnswers the open questions, oldest first.reads only
  4. Youreply to one yourself, and the bot sends it
    Web endpoint, your keyPOST /questions/reply
    Reply to a QuestionSends your reply to the customer's chat.changes a Questionsends 1 Telegram message
  • Web endpoint: your website or app calls it
  • Event: another service tells your backend

The rule you will want to change first

When no saved answer fits, the bot says a person will answer soon, and the question waits for you.

It lives in the action Answer a Message. Tell your agent how you want it instead: one sentence changes, and you read the change before it goes Live.

What it is made of

The map shows the records it keeps, the actions it runs and the services it calls.

What it keeps

Answerquestion, reply
Questionchat, name, text, state, answer

What it does

Add an Answerweb endpoint, your key
Answer a Messageon Telegram eventThe rule to change first
List Open Questionsweb endpoint, your key
Reply to a Questionweb endpoint, your key

What it reaches

TelegramSend messages through your own Telegram bot, and act on what people write to it.
AnthropicLet an action ask a Claude model to read, sort or write text.
Your website3 web endpoints

What it keeps

Answer

2 fields

One question customers ask, with the reply the bot sends.

question
required, at most 300 characters
reply
required, at most 4000 characters

Only your key saves answers. The bot reads them when a message arrives.

Question

5 fields

Each message a customer sent, and whether the bot answered it.

chat
required
name
optional, at most 120 characters
text
required, at most 4096 characters
state
required, one of open, answered
answer
optional

The bot keeps each message. Only your key reads them and replies.

What it does

Open an action to read its steps: each sentence, with the calls that do it under it.

Add an AnswerYou save a question customers ask and the reply the bot gives.

Who starts it

From the webPOST /answers

What it is given

Questiontext, needed

Replytext, needed

What it does

  • input.questionwhat the caller gives
  • answera value it works out
  • Answera record type
  • Answeran attribute of a record or an answer

Create an Answer with question and reply set to the given question and reply.

Add an Answer

set question to input.question

set reply to input.reply

Answer with that Answer's id.

Answer

id is answer.id

Answer a MessageA customer writes to the bot. When a saved answer fits, the bot sends it. Otherwise the question waits for you.

What it is given

Messagea record, needed

What it does

  • input.messagewhat the caller gives
  • incominga value it works out
  • Answera record type
  • textan attribute of a record or an answer
  • 10a fixed text or number
  • max tokensa part of an email or a payment

A message arrived on Telegram.It reads the chat, the sender's first name and the text of the message.

incoming is input.message

When the message has no text, such as a photo, stop.

When incoming.text holds no value

Answer

Find up to 100 Answers, oldest first.

answers is

Find all Answers

sorted by created_at, lowest first

Write each Answer as one line of its place in that list, from 1, and its question.

Write each Answer as one line of its place in that list, from 1, and its question.

Your agent wrote this rule

Ask Anthropic which line answers the text of the message, and take the number it names.If that call fails, or it names no number, the number is 0.

A model reads the customer's own words, so "when do you open" finds the answer to "What are your opening hours?".

choice is

Ask Anthropic to Create Message

max tokens is 10

messages is a list of 1:

content is the text

Questions: faq Message: incoming.text

role is "user"

model is "claude-haiku-4-5"

system is the text

Each line below is a number and a question. Reply with only the number of the line that answers the customer's message, or with 0 when none does.

when it fails, go on

picked is

when

choice holds a value

then

take choice.content

then take the text of its first item

then cut the spaces at its ends

then read it as a number

or, when that gives nothing, take 0

then round it to a whole number

otherwise 0

When the number is 1 or more, find the Answer at that place among the Answers, oldest first.

found is

Find all Answers

sorted by created_at, lowest first

When an Answer matches, send its reply to the chat on Telegram, and keep the message as a Question with state answered and answer_id set to that Answer's id.Otherwise, send "Thank you. A person will answer you here soon." to the chat on Telegram, and keep the message as a Question with state open.Each Question keeps the chat, the sender's first name and the text.

chat is "incoming.chat.id as a number"

When number of found is more than 0

Ask Telegram to Send Message

chat id is chat

text is the reply of the first item of the value named found

Add a Question

set answer_id to the id of the first item of the value named found

set chat_id to chat

set name to incoming.from.first_name

set state to "answered"

set text to incoming.text

Otherwise

Ask Telegram to Send Message

chat id is chat

text is "Thank you. A person will answer you here soon."

Add a Question

set chat_id to chat

set name to incoming.from.first_name

set state to "open"

set text to incoming.text

List Open QuestionsYou read the questions the bot could not answer, oldest first.

Who starts it

From the webGET /questions

What it is given

Nothing. It needs no input.

What it does

  • open_questionsa value it works out
  • Questiona record type
  • Questionan attribute of a record or an answer
  • "open"a fixed text or number

Find up to 100 Questions whose state is open, oldest first.

open_questions is

Find Questions where

state is "open"

sorted by created_at, lowest first

Answer with each Question's id, name, text and the time it was asked.

Answer

questions is

each question of open_questions as

asked_at is question.created_at

id is question.id

name is question.name

text is question.text

Reply to a QuestionYou answer a waiting question yourself, and the bot sends your reply to the customer's chat.

Who starts it

From the webPOST /questions/reply

What it is given

Question IDtext, needed

Replytext, needed

What it does

  • input.question_idwhat the caller gives
  • questiona value it works out
  • Questiona record type
  • Questionan attribute of a record or an answer
  • "answered"a fixed text or number
  • chat ida part of an email or a payment
  • refusewhere it says no

Find the Question whose id is the given question id.When none matches, refuse with "No such question".

question is

Find the first Question where

id is input.question_id

when none refuse "No such question"

Send the given reply to that Question's chat on Telegram.

Ask Telegram to Send Message

chat id is question.chat_id

text is input.reply

Change that Question's state to answered.

Change the Question where

id is question.id

set state to "answered"

Answer with that Question's id.

Answer

id is question.id

Web endpoints

What it doesWho may callAddress
Only you, with your key, save answers.you, with your keyPOST /answers
Only you, with your key, read the open questions.you, with your keyGET /questions
Only you, with your key, reply to a question.you, with your keyPOST /questions/reply

What it cannot do yet

  • It answers only from the answers you saved. It does not write new answers itself.
  • It reads text. A photo, a voice message or a sticker gets no answer.
  • Each message costs one short call to Anthropic, on your own Anthropic key.

Build the pages with your tool

Typestate is the backend. Paste this brief into Lovable, v0, Claude Code or the tool that builds your pages.

Show the brief
Build the pages for "FAQ bot on Telegram". The backend runs on Typestate and answers these web endpoints: POST /answers: Only you, with your key, save answers. Who may call: you, with your key. GET /questions: Only you, with your key, read the open questions. Who may call: you, with your key. POST /questions/reply: Only you, with your key, reply to a question. Who may call: you, with your key. People sign up at POST /auth/signup and sign in at POST /auth/login, which answers a token. Send it as Authorization: Bearer <token>. A refused call answers a sentence that can be shown to the person as it is.

Start it

  1. Tell your agent the sentence on the right.
  2. It tells you what only you can do in the cockpit. A key never goes through the agent.
  3. Open your Sandbox address and try it yourself.

Starting from this blueprint does not count against the action changes of your plan. The Free plan runs it on Sandbox. Live needs a paid plan.

Start the FAQ bot on Telegram blueprint on TypestateChoose a plan

Related blueprints