WxWorkRobot 2.0.4

dotnet add package WxWorkRobot --version 2.0.4
                    
NuGet\Install-Package WxWorkRobot -Version 2.0.4
                    
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="WxWorkRobot" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WxWorkRobot" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="WxWorkRobot" />
                    
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 WxWorkRobot --version 2.0.4
                    
#r "nuget: WxWorkRobot, 2.0.4"
                    
#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 WxWorkRobot@2.0.4
                    
#: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=WxWorkRobot&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=WxWorkRobot&version=2.0.4
                    
Install as a Cake Tool

WxWorkBot

企业微信机器人,开箱即用,无第三方依赖;目前已实现:

  • 纯文本消息
  • Markdown消息
  • 支持初始化回调Key,实例范围内修改回调Key,方法范围内修改回调Key,以在不同层面支持多个Bot

版本更新Tip

  • 2.0.4: 直接使用插值拼接消息,不再依赖Json序列化组件
  • 2.0.3: 支持方法级别设置回调Key
  • 2.0.2: 有几个关键变化,见下面2.0版本变化
  • 1.3.0: 替换掉Flurl.Http,因为其可能会出现不能向后兼容的情况

依赖注入

先安装 WxWorkRobot: alternate text is missing from this package README image

配置服务AddWxWorkBotService:

public void ConfigureServices(IServiceCollection services)
{
    //从配置文件加载配置进行依赖注入
    services.AddWxWorkBotService(context.Configuration);

    //直接指定参数
    //services.AddWxWorkBotService(
    //    webhookKey: "7b0a1288-1029-444e-9d50-22f1a9b17f47",
    //    sendingResponseLogLevel: Microsoft.Extensions.Logging.LogLevel.Information);

    //使用Option
    //services.AddWxWorkBotService(new WxWorkBotOptions()
    //{
    //    WebhookKey = "7b0a1288-1029-444e-9d50-22f1a9b17f47",
    //    SendingResponseLogLevel = Microsoft.Extensions.Logging.LogLevel.Information,
    //});
}

如果从配置文件加载配置进行依赖注入,appsettings.json中要配置有(其他支持配置的选项还有WebhookUrlTemplate/SendingResponseLogLevel):

"WxWorkRobot": {
  "WebhookKey": "7b0a1288-1029-444e-9d50-22f1a9b17f47"
}

使用

构造函数直接构造实例并使用,参考使用示例:

public class SampleService
{
    private readonly WxWorkBotClient client;

    public SampleService(WxWorkBotClient client)
    {
        this.client = client;
    }

    public async Task SendTextTest()
    {
        await client.SendText("测试");
    }
}

如果想要使用非默认调用Key(非初始化的调用Key):

private readonly WxWorkBotClient client;

public WxWorkBotClientTest(WxWorkBotClient client)
{
    this.client = client;
}

[Theory]
[InlineData("Test1")]
public async Task SendText(string text)
{
    //在实例范围内修改回调Key
    //client.SetKey("b19d3e0f-e7a6-4823-bf5b-462b8fa21d85");

    //在方法范围内修改回调Key
    await client.SendText(text, "b19d3e0f-e7a6-4823-bf5b-462b8fa21d85");
}

2.0版本变化

  • WxWorkRobot.MsDependency包不再使用,直接合并为一个WxWorkRobot包
  • 不再使用RestSharp或第三方HTTP客户端,RestSharp仍然可能有版本问题
  • 使用.NET 的 IHttpClientFactory的方式去发起HTTP请求
  • 加入日志输出等选项,具体见WxWorkBotOptions
  • 支持方法级别设置回调Key
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on WxWorkRobot:

Package Downloads
WxWorkRobot.MsDependency

企业微信机器人调用客户端的dotnet原生依赖注入扩展接入

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 245 11/29/2024
2.0.3 114 11/26/2024
2.0.2 101 11/26/2024
1.3.0 604 3/5/2024
1.2.0 177 1/22/2024
1.1.0 1,577 2/2/2023
1.0.0 494 2/1/2023

注意,从2.0开始不再依赖第三方Http客户端,也不再分成两个包,WxWorkRobot.MsDependency不再使用,详细改动见README