TelegramDataStorage 1.0.0
See the version list below for details.
dotnet add package TelegramDataStorage --version 1.0.0
NuGet\Install-Package TelegramDataStorage -Version 1.0.0
<PackageReference Include="TelegramDataStorage" Version="1.0.0" />
paket add TelegramDataStorage --version 1.0.0
#r "nuget: TelegramDataStorage, 1.0.0"
// Install TelegramDataStorage as a Cake Addin #addin nuget:?package=TelegramDataStorage&version=1.0.0 // Install TelegramDataStorage as a Cake Tool #tool nuget:?package=TelegramDataStorage&version=1.0.0
Telegram Data Storage
Store your data (config, session, etc.) in a telegram chat.
Description
This library allows you to store your data in Telegram itself.
It stores the serialized data in a Telegram chat message as a JSON file. The list of the stored files is stored in the channel's description.
When you save data, the library will create a new message with the data in the channel.
When you load data, the library will find the message, download the file, and deserialize the data. To retrieve the data, the library will forward the message to the same channel and delete it after downloading the file.
Usage
using TelegramDataStorage;
class SomeData : IStoredData
{
public static string Key => "MyBeautifulData";
public string SomeProperty { get; set; }
}
var serviceCollection = new ServiceCollection();
var config = new TelegramDataStorageConfig(
BotToken: "1234567890:ABCdefGhIjKlmnOpqrStuVwXyz1234567890",
ChatId: -1001234567890
);
serviceCollection.AddTelegramDataStorage(config);
var serviceProvider = serviceCollection.BuildServiceProvider();
var storage = serviceProvider.GetRequiredService<ITelegramDataStorage>();
var someData = new SomeData
{
SomeProperty = "Some value"
};
await storage.SaveAsync(someData);
var loadedData = await storage.LoadAsync<SomeData>();
Console.WriteLine(loadedData.SomeProperty);
Advanced usage
Basically, you only need to implement the IStoredData
interface and use the ITelegramDataStorage
service.
However, all classes are public and can be used directly or replaced with your own implementation.
For example, you can replace IDataConverter
with your own implementation to add encryption or compression.
Testing
To run integration tests, you need to create a new Telegram bot and a new channel.
Then, you need to set them in the appsettings.json
file and run dotnet test
.
To run them in docker, you need to pass the BOT_TOKEN
and CHAT_ID
arguments to docker build
.
Limitations:
- The data size of the result JSON string should be less than 20MB.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.