WM.MessengersForms 8.9.2

dotnet add package WM.MessengersForms --version 8.9.2
                    
NuGet\Install-Package WM.MessengersForms -Version 8.9.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WM.MessengersForms" Version="8.9.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WM.MessengersForms" Version="8.9.2" />
                    
Directory.Packages.props
<PackageReference Include="WM.MessengersForms" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WM.MessengersForms --version 8.9.2
                    
#r "nuget: WM.MessengersForms, 8.9.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WM.MessengersForms@8.9.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WM.MessengersForms&version=8.9.2
                    
Install as a Cake Addin
#tool nuget:?package=WM.MessengersForms&version=8.9.2
                    
Install as a Cake Tool

WM.MessengersForms

Опис

WM.MessengersForms — це бібліотека для створення інтерфейсів користувача для месенджерів. Вона дозволяє будувати екрани, повідомлення, кнопки, поля введення та багато іншого. Ви можете серіалізувати ці елементи у формати, що підтримуються популярними платформами, та створювати ланцюжки екранів за допомогою білдера.


Встановлення

Додайте пакет до вашого проекту за допомогою NuGet:

dotnet add package WM.MessengersForms

Приклади використання

Створення базових елементів

Приклад створення повідомлення, кнопки та поля введення:

using WM.MessengersForms.Elements;

var msg = new Message(new MessageOptions())
{
    Title = "HELLO WORLD TITLE",
    Text = "just hello world message",
    Order = 1,
    Id = 1
};

var btn = new Button(new ButtonOptions())
{
    Text = "Test btn",
    SubText = "Test sub btn text",
    Action = "TestAction",
    Id = 2,
    Order = 2
};

var phoneInput = new PhoneInput(new TextInputOptions()
{
    Color = "RED",
    InputTextStyle = "BOLD"
})
{
    Id = 3,
    Order = 3,
    PlaceHolder = "+38(068)000-00-00"
};

var screen = new Screen();
screen.AddElement(msg);
screen.AddElement(btn);
screen.AddElement(phoneInput);

var result = screen.ToMessengerFormat(MessengerFormat.Widget);
Console.WriteLine(result);

Приклад використання Builder для створення ланцюжків екранів

За допомогою Builder можна створювати складні інтерфейси:

using WM.MessengersForms.Chains;

var chain = new ChainController();

chain.CreateScreen("MainScreen", 0, true)
     .CreateButton("Button1", 1, 100, null, b => b
         .SetColor("red")
         .SetIcon("icon.png")
         .SetSubText("This is button 1"))
     .CreateButton("Button2", 2, 2, null, b => b
         .SetColor("blue")
         .SetImage("image.jpg"))
     .CreateMessage("message in mainscreen", 3, 3, m => m
         .SetTitle("TEST MESSAGE TITLE")
         .SetPhotoUrl("/photo.jpeg")
         .SetColor("RED").SetStyle("BOLD"))
     .AddChainLink("Акції");

chain.CreateScreen("SecondaryScreen", 1)
     .CreateButton("Back", 3, 1, "act:back_action", b => b
         .SetColor("green")
         .SetIcon("back_icon.png"))
     .AddChainLink("act:secondary_screen");

var mainScreen = chain.GetScreenByAction("Акції");
var secondaryScreen = chain.GetScreenByAction("act:secondary_screen");

Console.WriteLine(mainScreen.ToMessengerFormat(MessengerFormat.Widget));
Console.WriteLine(secondaryScreen.ToMessengerFormat(MessengerFormat.Widget));

Експорт та імпорт ланцюжків

Ланцюжки екранів можна експортувати та імпортувати:

var exportedData = chain.ExportChain();
Console.WriteLine(exportedData);

var newChain = ChainController.ImportChain(exportedData);
Console.WriteLine(newChain.GetScreenByAction("Акції").ToMessengerFormat(MessengerFormat.Widget));

Кастомна серіалізація

Ви можете додати власну логіку серіалізації, створивши клас, що реалізує інтерфейс IElementSerializer<T>:

public class CustomTelegramSerializer : IElementSerializer<TelegramMessageData>
{
    public TelegramMessageData Serialize(IDrawableElement element)
    {
        var model = (ISerializationModel)element.GetSerializationModel();

        switch (model.Type)
        {
            case "Screen":
                return ModelToTelegramSessage(model, 123);
            default:
                throw new NotSupportedException($"Type: {model.Type} not supported");
        }
    }

    private TelegramMessageData ModelToTelegramSessage(ISerializationModel model, long chatId)
    {
        ScreenSerializationModel screen = (ScreenSerializationModel) model;

        var serializationModels = screen.Elements.Cast<ISerializationModel>();
        var buttons = serializationModels
            .Where(sm => sm.Type.Equals(ElementType.Button.ToString()))
            .Cast<ButtonWidgetModel>().ToList();

        var message = (MessageSerializationModel)serializationModels
            .FirstOrDefault(sm => sm.Type.Equals(ElementType.Message.ToString()));

        var tgButtons = buttons.Select(b => new TelegramButton(b.Text, b.Action));

        return new TelegramMessageData(message?.Text, message?.PhotoUrl, null, chatId, tgButtons);
    }
}

Основні класи

  • Message: використовується для створення повідомлень.
  • Button: створення кнопок із текстом, підписами та діями.
  • PhoneInput: поле введення номеру телефону.
  • Screen: екран, який об’єднує елементи.
  • ChainController: менеджер ланцюжків екранів.
  • IElementSerializer: інтерфейс для серіалізації елементів.

Формати серіалізації

MessengerFormat.Widget

Серіалізація елементів у формат для віджетів месенджерів.

Кастомна серіалізація

Реалізуйте власний формат за допомогою інтерфейсу IElementSerializer<T>.


Ліцензія

WM.MessengersForms розповсюджується під ліцензією MIT License.


Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.9.2 97 9/4/2026
8.9.1 99 8/20/2026
8.9.0 125 8/17/2026
8.8.39 107 8/3/2026
8.8.37 129 6/26/2026
8.8.36 127 6/23/2026
8.8.34 121 6/15/2026
8.8.33 110 6/3/2026
8.8.32 114 6/3/2026
8.8.31 102 5/7/2026
8.8.30 101 5/6/2026
8.8.29 108 5/4/2026
8.8.28 106 5/4/2026
8.8.27 118 4/14/2026
8.8.26 106 4/14/2026
8.8.25 365 3/17/2026
8.8.24 122 3/10/2026
8.8.23 121 3/10/2026
8.8.22 163 3/9/2026
Loading failed