Telegram bot for getting weather using OpenWeather and demonstrating simple CRUD operation with MS-SQL Database over ADO.NET
- All source code written in C# .NET 6 as a console application using polling wrapper from: https://github.com/TelegramBots/Telegram.Bot.Examples
- MrRoundRobin Nuget package used in this project: https://www.nuget.org/packages/Telegram.Bot
All program configurations are located in the appsettings.json file in CrudBot.Main project You need to pass your Telegram token generated by @BotFather https://core.telegram.org/bots/faq#how-do-i-create-a-bot to the next section:
"BotConfiguration": {
"BotToken": "Your token"
}
To configure the database create it and just run the program after all steps of configuring:
"DatabaseConfiguration": {
"ConnectionString": "Your connection string"
}
For weather service, I used OpenWeather API 2.5 and GeoWeather Api: https://openweathermap.org/ Put your API key to the next section
"OpenWeatherApi": {
"BaseUrl": "https://api.openweathermap.org/data/2.5/weather?",
"ApiKey": "Your API key",
"TimeOut": "-1",
"BaseGeoUrl": "http://api.openweathermap.org/geo/1.0/direct?q=",
"GeoCityLimit": "1"
}
The bot works with the following commands:
- /fill_data - Put data into the database from user.json file. This file included in the solution
- /add_person - Add person into the database
- /get_persons - Get all persons from the database
- /edit_person - Edit person in the database
- /delete_person - Delete person by Id
- /delete_all - Delete all persons from the database
- /get_weather - Get current weather;