You can create Telegram bots using vals.
In this example, youโll create a val that uses the Web API to receive webhooks from Telegram.
When users message your bot, the bot will reply with the same message.
1. Create your bot by talking to @BotFather2. Add the bot token as a secret3. Check your token works4. Create a secret so you can verify webhooks5. Create a webhook handler to receive messages6. Tell your bot about the webhook handler7. Send a message to your bot to check it works!
1. Create your bot by talking to @BotFather
Speak to Telegramโs https://t.me/botfather to create your bot and obtain a bot token.
2. Add the bot token as a secret
Copy the bot token you just received and save it as a Val Town secret as
telegramBotToken
.3. Check your token works
Call
@vtdocs.telegramGetMe
with your newly created secret to check that it works.4. Create a secret so you can verify webhooks
Generate a random string and save it as a Val Town secret as
telegramWebhookSecret
.5. Create a webhook handler to receive messages
When Telegram users send messages to your bot, they will be forwarded to your webhook handler. Weโll use the secret we just created to verify that the message came from our bot.
Fork this val that uses the Web API :
6. Tell your bot about the webhook handler
Use
@vtdocs.telegramSetWebhook
to tell your bot where to send webhooks.7. Send a message to your bot to check it works!
It should echo back the message like this:
Not working? Try debugging the webhook handler you created via the Evaluations tab. Or get help on Val Townโs Discord.