3cx Tapi Server

This commit is contained in:
2026-03-18 11:27:11 +01:00
parent 7a99b1ab55
commit fe8fcdf45b
12 changed files with 363 additions and 0 deletions
@@ -0,0 +1,42 @@
using System.Threading.Tasks;
using CPATapi.Server.Models;
using Dapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
namespace CPATapi.Server.Controllers
{
[Route("[controller]")]
[ApiController]
public class CallerIdController : ControllerBase
{
private readonly IConfiguration _config;
public CallerIdController(IConfiguration config) => _config = config;
[HttpGet, Route("{number}")]
public async Task<TapiContact> CallerIdAsync([FromRoute] string number)
{
if (number.Length >= 5)
{
var minMatch = number[^5..];
number = "%" + minMatch;
}
await using var con = new SqlConnection(_config["Db:ConnectionString"]);
await con.OpenAsync();
var result = await con.QueryFirstOrDefaultAsync<TapiContact>(@"
SELECT
TD_ID,
TD_NAME,
TD_NUMBER,
TD_NUMBER_TAPI,
TD_MEDIUM
FROM dbo.CP_TAPI_DIRECTORY
WHERE TD_NUMBER_TAPI LIKE @number", new {number});
return result;
}
}
}