This project was created as a minimalistic portfolio project to showcase just a few of my coding skills, such as TDD, CI/CD workflows, IaC, serverless cloud apps, and clean coding practices.
This bot is designed to help you efficiently track and report your working time through a convenient and intuitive interface.
Try it live at @turbo_time_tracker_bot
I built this project to solve a common problem I faced in my personal and professional life - tracking the amount of time spent on work throughout the month. I found that traditional methods like using mobile apps were too complicated and lacked the convenience and real-time accessibility I needed. As an avid user of Telegram, I decided to create this bot to integrate seamlessly with my daily workflow. Now, tracking time has never been easier or more convenient!
To get started with the TimeTracker Telegram Bot, follow these simple steps.
To register your Telegram bot using BotFather, follow these steps:
-
Open Telegram and Start a Chat with BotFather:
- Search for
@BotFather
in the Telegram search bar or click this link to start a chat with BotFather.
- Search for
-
Create a New Bot:
- Type
/start
to begin the conversation with BotFather if you haven't already. - Type
/newbot
to create a new bot.
- Type
-
Choose a Name for Your Bot:
- BotFather will ask you for a name for your bot. This is the name that will be displayed to users.
- For example:
My Time Tracker Bot
-
Choose a Username for Your Bot:
- Next, you will be prompted to choose a username for your bot. The username must end in
bot
(e.g.,time_tracker_6709_bot
).
- Next, you will be prompted to choose a username for your bot. The username must end in
-
Receive Your Bot Token:
- After choosing the username, BotFather will provide you with an API token. This token is essential for interacting with the Telegram Bot API and must be kept confidential.
- Copy the token; you will need it to configure your bot in the next steps.
All the examples below use the bash
shell.
-
Clone this repository to your local machine:
git clone https://github.com/artemious7/TimeTrackerTelegramBot.git
-
Navigate into the project
src
directory:cd TimeTrackerTelegramBot/src
-
Register your Telegram bot via BotFather to get the API key and set Telegram Bot API key via the secrets file for the project:
dotnet user-secrets init TelegramApiKey=<Your_Api_Key> dotnet user-secrets set TelegramBotApiKey $TelegramApiKey
-
Install Azurite to use local storage account. If you want to use an Azure Storage account, add the connection string to the secrets file:
dotnet user-secrets set AzureWebJobsStorage <Your_Connection_String>
-
Build the project:
dotnet build
-
Install Azure Functions Core Tools and run the Function app locally:
func start
-
Use ngrok or other similar tool to direct Telegram to your app running locally.
ngrok http 7287
-
Copy the forwarding URL provided by ngrok and configure your Telegram bot webhook with the following command:
curl -F "url=<Your_Ngrok_URL>/api/ProcessUpdate" https://api.telegram.org/bot$TelegramApiKey/setWebhook
-
Send
/start
message to the Telegram bot.
If you are ready to deploy your bot to Azure, follow these steps:
- Install the Azure CLI: Azure CLI installation guide.
- Log in to your Azure account.
az login
- Create a new Function App in your resource group.
TelegramApiKey=<Your_Api_Key> rand=$RANDOM az group create \ --name TimeTrackerTelegramBot-rg \ --location northeurope az storage account create \ --resource-group TimeTrackerTelegramBot-rg \ --name timetrackersa$rand \ --location northeurope az functionapp create \ --resource-group TimeTrackerTelegramBot-rg \ --consumption-plan-location northeurope \ --runtime dotnet \ --functions-version 4 \ --name TimeTrackerTelegramBot-$rand \ --storage-account timetrackersa$rand # set app settings. Without these settings, Function app will be in error az functionapp config appsettings set \ --resource-group TimeTrackerTelegramBot-rg \ --name TimeTrackerTelegramBot-$rand \ --settings "TelegramBotApiKey=$TelegramApiKey" "dataContainerName=time-tracker-data-production"
- Install Azure Functions Core Tools.
- Deploy your code to Azure.
func azure functionapp publish TimeTrackerTelegramBot-$rand
- Get the
ProcessUpdate
function key to authorize the requests:code=$(az functionapp function keys list \ --resource-group TimeTrackerTelegramBot-rg \ --name TimeTrackerTelegramBot-$rand \ --function-name ProcessUpdate \ --query default \ --output tsv | tr -d '\r')
- Update the webhook setting on Telegram to point to your Azure-hosted endpoint.
curl -F "url=https://TimeTrackerTelegramBot-$rand.azurewebsites.net/api/ProcessUpdate?code=$code" https://api.telegram.org/bot$TelegramApiKey/setWebhook
Once the bot is up and running, you can interact with it via Telegram. Here are the commands and instructions to help you get started:
/start
: Welcome message and instructions on how to use the bot./help
: Detailed instructions on how to log your time./reset
: Reset the total recorded time./showTotal
: Display the total recorded time./undo
: Undo the last recorded time entry.- Logging Time: You can log time by simply sending messages in the format
1:35
,15:45 - 16:20
, or-0:20
to subtract time.
Here are some ways you can contribute:
- Report Issues: Use the GitHub issue tracker to report bugs or suggest improvements.
- Submit Pull Requests: Fork the repository, implement your changes, and submit a pull request for review.
- Share Ideas: Feel free to share your ideas for new features and improvements.
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b feature-name
- Commit your changes:
git commit -m "Description of your feature or fix"
- Push to the branch:
git push origin feature-name
- Submit a pull request through GitHub.
Thank you for contributing to the TimeTracker Telegram Bot!
This project is licensed under the MIT License. See the LICENSE file for more details.