|
1 | | -# gopray 🙏 |
| 1 | +# prayer-bot 🙏 |
2 | 2 |
|
3 | | -A Telegram Bot to get muslim prayers time, And subscribe to get notified on the prayers time |
| 3 | +A serverless Telegram bot that provides Muslim prayer times and sends notifications when prayers are approaching. |
4 | 4 |
|
5 | | - |
6 | | -[](https://wakatime.com/badge/user/965e81db-2a88-4564-b236-537c4a901130/project/5b8bc34a-26b1-4a61-be8d-f9b854b1e43a) |
| 5 | +[](https://wakatime.com/badge/user/965e81db-2a88-4564-b236-537c4a901130/project/635dffc4-6a06-4e43-9a87-5bb977437cdb) |
7 | 6 | [](https://goreportcard.com/report/github.com/escalopa/gopray) |
8 | | -[](https://codecov.io/gh/escalopa/gopray)<img src="./cover.jpg"> |
9 | 7 |
|
10 | | -## Contributing 🤼 |
| 8 | + |
11 | 9 |
|
12 | | -Before we start talking about the bot, I would really appreciate if you can contribute to this project by adding more features or fixing bugs. It is totally open source and free to use. 😁 |
| 10 | +## Currently Available Cities |
13 | 11 |
|
14 | | -## Usecase 🛠️ |
| 12 | +| City | Bot | |
| 13 | +|-----------|------------------------------------------------------------| |
| 14 | +| Kazan | [@kazan_prayer_bot](https://t.me/kazan_prayer_bot) | |
| 15 | +| Innopolis | [@innopolis_prayer_bot](https://t.me/innopolis_prayer_bot) | |
15 | 16 |
|
16 | | -```mermaid |
17 | | -graph LR |
18 | | -A[User] --> |Get Prayers Time| B((Bot)) |
19 | | -A[User] --> |Subscribe To Bot| B((Bot)) |
20 | | -A[User] --> |Change Bot Language| B((Bot)) |
21 | | -B((Bot)) --> |Notify Users about prayers| B((Bot)) |
22 | | -A[User] --> |Send Feedback Messages\nOr Bug Reports| B((Bot)) |
23 | | -B((Bot)) --> |Store Prayers Time| D[[Run Time Memory]] |
24 | | -B((Bot)) --> |Store User ID For Subscriptions| C[[Database]] |
25 | | -``` |
| 17 | +--- |
| 18 | + |
| 19 | +## Architecture 🏗️ |
26 | 20 |
|
27 | | -## Subscription Feature 📢 |
| 21 | +This bot is completely serverless, utilizing Yandex Cloud Functions for operation and YDB for data storage. |
28 | 22 |
|
29 | | -This feature allows the bot to notify users `20 min` before the prayers time. (Time is set by the `UPCOMING_REMINDER` env variable) |
| 23 | + |
30 | 24 |
|
31 | | -Users can subscribe to the bot by sending `/subscribe` command to the bot. And unsubscribe by sending `/unsubscribe` command to the bot. |
| 25 | + |
32 | 26 |
|
33 | | -Also on friday the bot will remind the user to pray Gomaa prayer. at `7:00 PM` (Time is set by the `GOMOAA_REMINDER_HOUR` env variable), This is value to when to remind them, The prayer time is calculated based on the prayers time of the day and sent to the user. |
| 27 | +For infrastructure configuration details, check the [terraform file](./main.tf). |
34 | 28 |
|
35 | | -### How it works 🤔 |
| 29 | +--- |
36 | 30 |
|
37 | | -In order to implement this feature, We have to make to bot wait until `20 min` are left before the prayer's time. And then send a notification to the subscribed users. |
| 31 | +## Configuration 🛠️ |
38 | 32 |
|
39 | | -Also, when the time of the prayer's arrive we should also notify them. |
| 33 | +Bot configuration is managed through environment variables. |
40 | 34 |
|
41 | | -So for that I use simple `channels` to sleep the goroutine until the time is right to send the notification. |
| 35 | +Below is an example of an `APP_CONFIG` value containing all bot information: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "648252": { |
| 40 | + "bot_id": 648252, // Bot ID |
| 41 | + "owner_id": 1385434843, // Bot owner ID |
| 42 | + "location": "Europe/Moscow", // Timezone of the city |
| 43 | + "token": "oa7GmLW3fncbOE0MTfV0mKxH/F37cShhxgZ1mjl614w", // Telegram token |
| 44 | + "secret": "Noe&uPcwjaAxjqJU_JP4C^g2V7ZDQX" // Secret key to verify requests |
| 45 | + }, |
| 46 | + ... |
| 47 | +} |
| 48 | +``` |
42 | 49 |
|
43 | | -The first sleep is until the `20 min` before the prayer's time. And the second is until the prayer's time. |
| 50 | +- To find your owner ID, use [ID bot](https://t.me/myidbot) |
| 51 | +- Bot ID is the first number before `:` in the bot token |
| 52 | + - TOKEN: `123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11` |
| 53 | + - Bot ID: `123456789` |
44 | 54 |
|
45 | | -for more details check the [notifier code](./telegram/internal/adapters/notifier/notifier.go). |
| 55 | +--- |
46 | 56 |
|
47 | | -## Bot Options 🤖 |
| 57 | +## Bot Features 🤖 |
48 | 58 |
|
49 | | -### Default Commands 📝 |
| 59 | +### User Commands 📝 |
50 | 60 |
|
51 | | -| Command | Description | |
52 | | -|--------------|-----------------------------------------------------| |
53 | | -| /help | Get help message showing all possible commands | |
54 | | -| /prayers | Get prayers time | |
55 | | -| /date | Get prayers time by date | |
56 | | -| /subscribe | Subscribe to get notified on the prayers time | |
57 | | -| /unsubscribe | Unsubscribe to not get notified on the prayers time | |
58 | | -| /lang | Change the bot language (Default English) | |
59 | | -| /feedback | Send feedback to the bot owner | |
60 | | -| /bug | Report a bug to the bot owner | |
| 61 | +| Command | Description | |
| 62 | +|-------------|-----------------------------------------| |
| 63 | +| today | Get today's prayer times | |
| 64 | +| date | Get prayer times for a specific date | |
| 65 | +| next | Find out the next prayer time | |
| 66 | +| subscribe | Subscribe to daily reminders | |
| 67 | +| unsubscribe | Unsubscribe from daily reminders | |
| 68 | +| remind | Set reminder offset for the next prayer | |
| 69 | +| language | Change the bot language | |
| 70 | +| help | Show help message | |
| 71 | +| bug | Report a problem to bot owner | |
| 72 | +| feedback | Send feedback to bot owner | |
61 | 73 |
|
62 | 74 | ### Admin Commands 📝 |
63 | 75 |
|
64 | | -| Command | Description | |
65 | | -|----------|------------------------------------| |
66 | | -| /subs | Get subscribers count | |
67 | | -| /sall | Send message to all subscribers | |
68 | | -| /respond | Respond to feedback or bug message | |
| 76 | +| Command | Description | |
| 77 | +|----------|---------------------------------------| |
| 78 | +| admin | Show admin help message | |
| 79 | +| stats | View bot usage statistics | |
| 80 | +| announce | Send message to all users | |
| 81 | +| reply | Reply to user's bug/feedback message | |
| 82 | + |
| 83 | +--- |
69 | 84 |
|
70 | 85 | ## References 📚 |
71 | 86 |
|
72 | | -- [Telegram API (Telego)](https://github.com/SakoDroid/telego) |
73 | | -- [Prayer Times Site](http://dumrt.ru/ru/help-info/prayertime/) |
| 87 | +- [go-telegram](https://github.com/go-telegram) |
| 88 | +- [telegram-api](https://core.telegram.org/bots/api) |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## How to Contribute 🤝 |
| 93 | + |
| 94 | +### [1] Add a City |
| 95 | + |
| 96 | +You do: |
| 97 | +1. Get prayer times for a city in CSV format |
| 98 | +2. Make a pull request (or open an issue) with the new file |
| 99 | + |
| 100 | +I do: |
| 101 | +1. Create a new Telegram bot |
| 102 | +2. Upload the city file to storage bucket |
| 103 | + |
| 104 | +### [2] Add a Language |
| 105 | + |
| 106 | +You do: |
| 107 | +1. Create translation text for the following files: |
| 108 | + - [./serverless/reminder/internal/handler/languages/text.yaml](./serverless/reminder/internal/handler/languages/text.yaml) |
| 109 | + - [./serverless/dispatcher/internal/handler/languages/en.yaml](./serverless/dispatcher/internal/handler/languages/en.yaml) (replace `en` with the new language code) |
| 110 | + |
| 111 | +I do: |
| 112 | +1. Deploy a new version of the code |
74 | 113 |
|
| 114 | +### [3] Code Contributions |
75 | 115 |
|
76 | | -## Upcoming Features 🚀 |
| 116 | +Found a bug? Want to add a new feature? Just open an issue or submit a pull request. |
77 | 117 |
|
78 | | -### Version 1 Milestones 🏁 |
79 | | -- [x] Support date format for `/prayersdate` command with leading zeros and with delimiters (. / -) |
| 118 | +--- |
| 119 | + |
| 120 | +## Development Roadmap 🚀 |
| 121 | + |
| 122 | +### V1 ✅ |
| 123 | +- [x] Support date format for `/prayersdate` command with leading zeros and delimiters (. / -) |
80 | 124 | - [x] Implement subscriptions & notifications |
81 | 125 | - [x] Update text messages to be more user-friendly |
82 | 126 |
|
83 | | -### Version 2 Milestones 🏁 |
84 | | -- [x] store prayers time in memory to reduce the number of requests to the database since the prayers time is not changing |
85 | | -- [x] make response endpoint for admin to respond to feedback & bug messages |
86 | | -- [x] remind about gomaa prayer on friday |
| 127 | +### V2 ✅ |
| 128 | +- [x] Store prayer times in memory to reduce database requests |
| 129 | +- [x] Add response endpoint for admin to address feedback & bug messages |
| 130 | +- [x] Add Jumu'ah prayer reminders on Fridays |
87 | 131 |
|
88 | | -### Version 3 Milestones 🏁 |
| 132 | +### V3 ✅ |
89 | 133 | - [x] Add time keyboard to `/date` command |
90 | | -- [x] Remove selection message for `/date` & `/lang` after the use interacts with the message or timeout |
91 | | -- [x] On new user commands terminate other going channels that are listening to the chat |
92 | | -- [x] Add feature to delete old prayer time message when new one is sent |
93 | | -- [x] Add feature to send all subscribers a message from admin |
94 | | -- [x] Add feature to get count of subscribers for admin |
| 134 | +- [x] Remove selection message for `/date` & `/lang` after user interaction or timeout |
| 135 | +- [x] Terminate other active channels when user sends new commands |
| 136 | +- [x] Add feature to delete old prayer time message when a new one is sent |
| 137 | +- [x] Enable admins to broadcast messages to all subscribers |
| 138 | +- [x] Add feature to get subscriber count for admins |
95 | 139 | - [x] Write more robust tests for core features |
96 | 140 |
|
97 | | -### Version 4 Milestones 🏁 |
98 | | -- [x] Add different languages support (AR, RU, TT, TR, UZ) |
99 | | -- [x] Use script messages in the bot |
100 | | -- [x] Set user script before command if nor set |
101 | | -- [x] USe script commands in notifications |
102 | | -- [x] Fix prayers timetable for other languages |
103 | | - |
104 | | -### Version 5 Milestones 🏁 |
105 | | -- [x] Refactor the code to be more readable and maintainable |
106 | | -- [x] Enhance logging to be more informative and useful |
107 | | -- [x] Enable using many bot in the same code |
| 141 | +### V4 ✅ |
| 142 | +- [x] Add multi-language support (AR, RU, TT, TR, UZ) |
| 143 | +- [x] Implement script messages in the bot |
| 144 | +- [x] Set user script before command if not set |
| 145 | +- [x] Use script commands in notifications |
| 146 | +- [x] Fix prayer timetables for other languages |
| 147 | + |
| 148 | +### V5 ✅ |
| 149 | +- [x] Refactor code for better readability and maintainability |
| 150 | +- [x] Enhance logging to be more informative |
| 151 | +- [x] Enable using multiple bots with the same codebase |
| 152 | + |
| 153 | +### V6 ✅ |
| 154 | +- [x] Migrate to serverless architecture |
| 155 | +- [x] Automate deployment using Terraform |
| 156 | +- [x] Add support for multiple cities |
| 157 | +- [x] Add Spanish & French language support |
| 158 | +- [x] Add `/stats` command for bot usage statistics |
| 159 | + |
| 160 | +### V7 🔄 |
| 161 | +- [ ] Add support for all major world cities |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Development Setup 🖥️ |
| 166 | + |
| 167 | +Deploy bot on Yandex Cloud: |
| 168 | + |
| 169 | +```bash |
| 170 | +export ENV=dev # or prod |
| 171 | +./_scripts/init.sh $ENV prayer-bot |
| 172 | +terraform workspace select -or-create=true $ENV |
| 173 | +terraform apply # -auto-approve |
| 174 | +./_scripts/hook.sh |
| 175 | +``` |
| 176 | +
|
| 177 | +Generate Terraform dependencies visualization: |
| 178 | +
|
| 179 | +```bash |
| 180 | +terraform plan -out plan.out |
| 181 | +terraform show -json plan.out > plan.json |
| 182 | +docker run --rm -it -p 9000:9000 -v $(pwd)/plan.json:/src/plan.json im2nguyen/rover:latest -planJSONPath=plan.json |
| 183 | +``` |
0 commit comments