PBX API Control is a simple example gRPC API implementation for the 3CX PBX system written in C#.
{
"AllowedHosts": "*",
"DefaultCulture": "en-US",
"WhitelistedIPs": ["127.0.0.1"],
"Kestrel": {
"EndpointDefaults": {
"Url": "http://127.0.0.1:2838",
"Protocols": "Http2"
}
},
"Jwt": {
"Key": "0358a93d3fcf35a970bc7a62a3445be47d9443ac09852bc251b457ae4c7b3def",
"Issuer": "pac",
"Audience": "onvoip.ru"
}
}If the configuration file path differs from the default, it must be adjusted depending on the operating system:
if (OperatingSystem.IsWindows())
{
return @"C:\ProgramData\3CX\Bin\3CXPhoneSystem.ini";
}
else if (OperatingSystem.IsLinux())
{
return "/var/lib/3cxpbx/Bin/3CXPhoneSystem.ini";
}Files in the Protos/ folder define methods for managing:
- Calls (
call.proto) - Contacts (
contact.proto) - Extensions (
extension.proto) - IVR (
ivr.proto) - Queues (
queue.proto) - Ring Groups (
ring-group.proto) - SQL Queries (
sql.proto)
- Download and install Microsoft .NET 8.0.
- Build the project:
dotnet build pbx-call-control.csproj- Install .NET SDK 8.0:
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update \
&& sudo apt-get install -y apt-transport-https \
&& sudo apt-get update \
&& sudo apt-get install -y dotnet-sdk-8.0- Before compiling, edit the
WebAPICore.csprojfile:
Remove the line:
<Private>false</Private>And modify the path:
<ItemGroup>
<Reference Include="3cxpscomcpp2">
<HintPath>/usr/lib/3cxpbx/3cxpscomcpp2.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>- Run the following command to publish the project:
dotnet publish -c ReleaseTo enable IP and token restriction:
- Uncomment the following line in
Program.cs:
// app.UseMiddleware<AuthMiddleware>(); // Add authentication middleware- Obtain a token using the
GenerateTokenmethod.