Skip to main content
Serverless Prayer Telegram Bot
  1. Posts/

Serverless Prayer Telegram Bot

·500 words·3 mins· loading · loading · · ·
Go Yandex-Cloud Ydb S3 Serverless Telegram
Table of Contents
How I built a serverless prayer time bot on Telegram using Yandex Cloud.

escalopa/prayer-bot

A serverless Telegram bot that provides Muslim prayer times and sends notifications when prayers are approaching.

Go
1
1

Problem

  • As a Muslim, I strive to pray on time, but my busy schedule sometimes causes me to miss prayer times.
  • Although many apps are available for prayer reminders, as a developer, I spend most of my time on a laptop.
  • I wanted a way to receive prayer notifications directly on my laptop.
  • Since I was already using Telegram extensively, I decided to build a Telegram bot that would send me prayer time notifications.

Now that you have the context, let’s dive into how I built this bot.

Serverless

The bot is designed to be serverless, meaning it runs entirely in a cloud environment without the need for dedicated servers or manual infrastructure management.

This approach provides:

  • Easy deployment
  • Automatic scaling
  • Cost efficiency (which is why I migrated from a VPS to a serverless setup)

Here’s an overview of the bot’s architecture:

Architecture

ComponentPurpose
dispatcherHandles incoming messages and user interactions.
reminderSends prayer time reminders to subscribed users.
loaderLoads prayer times from S3 and stores them in YDB.

YDB

I chose YDB for several reasons:

  • Serverless: No need to manage virtual machines, clusters, or scaling — you pay only for what you use.
  • SQL Support: YDB supports familiar SQL queries, making integration straightforward without complex query builders.
  • Cost: It’s free up to a generous quota — perfect for prototyping and small-to-medium scale applications.
  • Exploration: I wanted to explore new technology and expand my database experience beyond PostgreSQL and MongoDB.

The bot uses two main tables:

chats table

ColumnTypePurpose
chat_idInt64Unique identifier for the Telegram chat.
bot_idInt64Unique identifier for the bot instance.
language_codeUtf8Language selected by the user for localized messages.
stateUtf8Current user interaction state (e.g., awaiting input, viewing results).
reminder_offsetInt32Time offset for prayer reminders (in minutes).
reminder_message_idInt32ID of the reminder message sent (used to delete old reminders).
subscribedBoolWhether the user is subscribed to notifications.
subscribed_atDatetimeTimestamp of when the user subscribed.
created_atDatetimeTimestamp of when the chat record was created.

prayers table

ColumnTypePurpose
bot_idInt64Unique identifier for the bot instance.
prayer_dateDateDate for which prayer times are calculated.
fajrDatetimeFajr prayer time.
shuruqDatetimeShuruq (sunrise) time.
duhrDatetimeDuhr prayer time.
asrDatetimeAsr prayer time.
maghribDatetimeMaghrib prayer time.
ishaDatetimeIsha prayer time.

Languages

The bot supports multiple languages for user interaction.

Translation templates are located in: serverless/dispatcher/internal/handler/languages/

Currently supported languages:

  • Arabic (ar)
  • English (en)
  • Spanish (es)
  • French (fr)
  • Russian (ru)
  • Turkish (tr)
  • Tatar (tt)
  • Uzbek (uz)

Each language is represented as a YAML file containing the necessary translations.

Deployment

As mentioned earlier, the bot runs serverlessly on Yandex Cloud.

For infrastructure management, I used Terraform to provision all necessary resources.

You can view the Terraform configuration file here.