DoodSoft.CallCenterApi 2.0.4

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

CallCenterApi

该组件包主要用于对接广州多度软件科技有限公司的AXB直拨、双向回拨、SIP直拨以及AI外呼平台,方便快速集成到自己的呼叫系统

支持.net版本

  • .net 6.0 以上
  • .net framework 4.6.1 以上

使用方法

1、注册组件

// 注册内存缓存服务,仅AI外呼时才需要,需引用依赖包:Microsoft.Extensions.Caching.Memory,也可以注入其它 IDistributedCache 缓存实现,例如 Redis,可以使用 services.AddDistributedRedisCache
//services.AddDistributedMemoryCache();
// 注册呼叫中心组件
services.AddCallCenter();

2、配置接口身份验证凭证

//方案1:直接创建凭证信息
var verify = new Verify("accessKey", "accessSecret");//接口凭证信息
//可以指定服务地址,也可以在注册呼叫中心组件时全局指定地址,请参考后续章节说明,优先使用 Verify 中的服务地址,不指定时将使用全局地址
//var verify = new Verify("https://xxx.com", "accessKey", "accessSecret");

// 方案2:使用密钥容器全局统一管理,后续使用时,根据条件获取对应的密钥
// 需要引入依赖包 Microsoft.Extensions.Configuration.Json
// 创建 IConfiguration 实例,从配置文件中加载凭证,一个线路可以多个凭证
var builder = new ConfigurationBuilder().AddInMemoryCollection()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var configuration = builder.Build();
var verifyService = ServiceProvider.GetRequiredService<VerifyContainer>();
verifyService.SetVerify(ApiLineType.AXB, configuration.GetSection("CallCenterApiSettings:AXB").Get<Verify[]>());
verifyService.SetVerify(ApiLineType.SIP, configuration.GetSection("CallCenterApiSettings:SIP").Get<Verify[]>());
verifyService.SetVerify(ApiLineType.AI, configuration.GetSection("CallCenterApiSettings:AI").Get<Verify[]>());

// 获取指定线路所有凭证
//var verifyList = verifyService.GetVerify(ApiLineType.AXB);
// 获取指定线路所有座席,一般用于给员工分配电话座席时,需要选择电话座席
//var agentList = verifyService.GetAllAgentInfoByLineType(ApiLineType.AXB);
// 根据座席ID获取对应的凭证,一般用于拨打电话时,可以直接根据员工电话座席ID获取到凭证
//var verify = verifyService.GetVerifyByAgentId(ApiLineType.AXB, 1001);
// 根据座席手机号或SIP分机号获取线路凭证,一般用于拨打电话时,可以直接根据员工的座席号码获取到凭证
//var verify = verifyService.GetVerifyByAgentPhone(ApiLineType.AXB, "13888888888");
// 根据座席手机号或SIP分机号获取对应的座席ID,一般用于拨打电话时,通过号码转换为座席ID
//var agentId = verifyService.GetAgentIdByPhone(ApiLineType.AXB, "13888888888");
// 根据座席手机号或SIP分机号获取对应的凭证和座席ID,好处是一次性获取,无需多调用
var valueTuple = await verifyService.GetVerifyAndAgentIdByAgentPhone(ApiLineType.AXB, "13888888888");
Debug.WriteLine(valueTuple.Verify);//接口凭证,可能为null
Debug.WriteLine(valueTuple.AgentId);//座席ID
if(valueTuple.AgentId == null)
{
    Debug.WriteLine($"主叫号码 【13888888888】 未开通座席,请咨询客服人员");
}

// 根据凭证Key获取凭证信息
//var verify = service.GetVerifyByAccessKey(ApiLineType.AXB, "accessKey");

配置文件参考样式:

{
  "CallCenterApiSettings": {
    "AXB": [{
      "AccessKey": "key1",
      "AccessSecret": ""
    },{
      "AccessKey": "key2",
      "AccessSecret": ""
    }],
    "SIP": [{
      "AccessKey": "",
      "AccessSecret": ""
    }],
    "AI": [{
      "AccessKey": "",
      "AccessSecret": ""
    }]
  }
}

3、业务调用

var type = ApiLineType.AXB;

//参考第2步中的方案,获取凭证信息,也可以直接创建
var verify = new Verify("accessKey", "accessSecret");//接口凭证信息

// 查询余额
var service = ServiceProvider.GetRequiredKeyedService<ICallCenterBase>(type);
var result = await service.GetBalance(verify);
Debug.WriteLine($"{result.Success} {result.Message}");
Debug.WriteLine($"用户余额为 {result.Data.Balance.ToString()}");

// 发起呼叫
var service = ServiceProvider.GetRequiredKeyedService<ICallCenter>(type);
var result = await service.CallNumber(verify, callNumber);
Debug.WriteLine($"{result.Success} {result.Message}");
if (result.Success)
{
    Debug.WriteLine($"BindId: {result.Data.BindId} 座席ID:{result.Data.AgentId} 座席号码: {callNumber.Caller} 小号/分机号: {result.Data.ExtNumber}");
}

// 获取座席列表
var service = ServiceProvider.GetRequiredKeyedService<ICallCenter>(type);
var result = await service.GetAgent(verify);
Debug.WriteLine($"{result.Success} {result.Message}");

//解析推送话单,在WebApi控制器中增加以下代码,要求能匿名访问

/// <summary>
/// 获取请求的上下文信息
/// </summary>
/// <returns></returns>
private async Task<ApiHttpContext> GetApiHttpContext()
{
    var body = await this.ActionContext.Request.Content.ReadAsStringAsync();
    var nameValueCollection = new NameValueCollection();
    foreach (var item in this.ActionContext.Request.Headers)
    {
        nameValueCollection.Add(item.Key, item.Value.FirstOrDefault());
    }
    var httpContext = new ApiHttpContext(this.ActionContext.Request.RequestUri.ToString(),
        this.ActionContext.Request.Method.Method, nameValueCollection, body);
    return httpContext;
}

/// <summary>
/// 用于AXB系统话单推送
/// </summary>
/// <returns></returns>
[HttpPost, ActionName("callLogs")]
public async Task<IHttpActionResult> CallLogs()
{
    ApiHttpContext httpContext = null;
    httpContext = await GetApiHttpContext();
    var callcenter = ServiceProvider.GetRequiredKeyedService<ICallCenter>(ApiLineType.AXB);
    var cmd = callcenter.GetCmd(httpContext);
    if (cmd == ApiCommand.PushCallInfo)
    {
        var list = callcenter.ResolveCallInfo(httpContext);
        if (list != null)
        {
            foreach (var callerDto in list)
            {
                //保存话单到数据库
                SaveCallCdr(callerDto);
            }
        }
    }
    this.ActionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
    {
        Content = new StringContent(httpContext.Response, Encoding.UTF8, "application/json")
    };
    return this.ResponseMessage(this.ActionContext.Response);
}



/// <summary>
/// 用于SIP系统话单推送
/// </summary>
/// <returns></returns>
[HttpPost, ActionName("pushCallDetail")]
public async Task<IHttpActionResult> PushCallDetail()
{
    ApiHttpContext httpContext = await GetApiHttpContext();
    var callcenter = ServiceProvider.GetRequiredKeyedService<ICallCenter>(ApiLineType.SIP);
    var cmd = callcenter.GetCmd(httpContext);
    if (cmd == ApiCommand.PushCallInfo)
    {
        var list = callcenter.ResolveCallInfo(httpContext);
        if (list != null)
        {
            foreach (var callerDto in list)
            {
                //保存话单到数据库
                SaveCallCdr(callerDto);
            }
        }
    }
    this.ActionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
    {
        Content = new StringContent(httpContext.Response, Encoding.UTF8, "application/json")
    };
    return this.ResponseMessage(this.ActionContext.Response);
}

/// <summary>
/// 用于AI系统话单推送
/// </summary>
/// <returns></returns>
[HttpPost, ActionName("aiCallback")]
public async Task<IHttpActionResult> AiCallback()
{
    ApiHttpContext httpContext = await GetApiHttpContext();
    var callcenter = ServiceProvider.GetRequiredKeyedService<IAiCallCenter>(ApiLineType.AI);
    var cmd = callcenter.GetCmd(httpContext);
    if (cmd == ApiCommand.PushCallInfo)
    {
        var aiCallInfo = callcenter.ResolveCallInfo(httpContext);
        if (aiCallInfo != null)
        {
            //保存话单到数据库
            SaveCallCdr(aiCallInfo);
        }
    }
    else if (cmd == ApiCommand.CallTaskInfo)
    {
        var taskStatusInfo = callcenter.ResolveTaskStatusInfo(httpContext);
        if (taskStatusInfo != null)
        {
            //保存任务状态到数据库
            SaveCallTaskByTaskId(taskStatusInfo.TaskId);
        }
    }
    this.ActionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
    {
        Content = new StringContent(httpContext.Response, Encoding.UTF8, "application/json")
    };
    return this.ResponseMessage(this.ActionContext.Response);
}

自定义服务地址

注意:默认无需指定服务地址,组件自身已内置服务地址,如果需要动态设置服务地址,可以使用以下几种方式:

// 注册 HttpClient 服务时,可以指定 HttpClient 名称,以及各个服务的地址
Services.AddCallCenter(cfg =>
{
    cfg.AXB_ServerUrl = "https://axb.xxx.com";
    cfg.SIP_ServerUrl = "https://sip.xxx.com";
    cfg.AI_ServerUrl = "https://aicall.xxx.com";
});
// 在业务代码中动态从数据库或配置文件中取值并设置到配置中
var options = ServiceProvider.GetRequiredService<IOptions<CallCenterOptions>>();
options.Value.AXB_ServerUrl = "https://axb.xxx.com";
options.Value.SIP_ServerUrl = "https://sip.xxx.com";
options.Value.AI_ServerUrl = "https://aicall.xxx.com";

// 在创建接口凭证时,指定服务地址
var verify = new Verify("https://xxx.com", "accessKey", "accessSecret");

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

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
2.0.4 221 5/15/2025