Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
push:
branches:
- main
- dev

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
10.0.x

- name: Build
run: dotnet build src/Max.BotClient/Max.BotClient.csproj -c Release

- name: Test
run: dotnet test tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj -c Release --no-build

publish:
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/main'
environment: main

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
10.0.x

- name: Pack
run: dotnet pack src/Max.BotClient/Max.BotClient.csproj -c Release -o ./artifacts

- name: Push to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
44 changes: 44 additions & 0 deletions src/Max.BotClient/Max.BotClient.DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if NET10_0_OR_GREATER
using System;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Max.BotClient
{
public static class BotClientServiceCollectionExtensions
{
/// <summary>
/// Регистрирует <see cref="BotClient"/> и <see cref="IBotClient"/> в DI-контейнере.
/// </summary>
/// <param name="services">Коллекция сервисов.</param>
/// <param name="token">Токен бота.</param>
/// <param name="configure">Дополнительная настройка параметров (RetryCount, RetryDelaySeconds и др.).</param>
public static IServiceCollection AddMaxBotClient(
this IServiceCollection services,
string token,
Action<BotClientOptions>? configure = null)
{
ArgumentNullException.ThrowIfNull(services);

var options = new BotClientOptions(token);
configure?.Invoke(options);

services.TryAddSingleton(options);

services.AddHttpClient("MaxBotClient");

services.TryAddSingleton<IBotClient>(sp =>
{
var factory = sp.GetRequiredService<IHttpClientFactory>();
var httpClient = factory.CreateClient("MaxBotClient");
return new BotClient(options, httpClient);
});

services.TryAddSingleton<BotClient>(sp => (BotClient)sp.GetRequiredService<IBotClient>());

return services;
}
}
}
#endif
11 changes: 9 additions & 2 deletions src/Max.BotClient/Max.BotClient.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net10.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<Version>1.0.1</Version>


<PackageId>Max.BotClient</PackageId>
<Authors>Deskri</Authors>
<Description>SDK for MAX Bot API (.NET Standard 2.0)</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Deskri/Max.BotClient</PackageProjectUrl>
<RepositoryUrl>https://github.com/Deskri/Max.BotClient</RepositoryUrl>
<PackageTags>max;bot;api;sdk</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -23,4 +25,9 @@
<PackageReference Include="System.Text.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
Loading