When using SIPSorcery with .NET 6 to make SIP calls via VoIP.ms, the custom Caller ID is not being passed correctly, despite being set in the code.
We have the setting configured in VoIP.ms as:
“I use a system capable of passing its own CallerID”
using ConsoleApp.Sipsorcery;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Serilog;
using Serilog.Extensions.Logging;
using SIPSorcery.Media;
using SIPSorcery.SIP;
using SIPSorcery.SIP.App;
public class Program
{
private static Microsoft.Extensions.Logging.ILogger _logger = NullLogger.Instance;
const string destination = "DESTINATION_NUMBER";
const string username = "USERNAME";
const string password = @"PASSWORD";
const string domain = "xxxxx.voip.ms";
// Internal variable for Caller ID
private static string callerId = "OWN_CALLER_ID";
public static async Task Main(string[] args)
{
AddConsoleLogger();
_logger.LogInformation("SIP Get Started");
var userAgent = new SIPUserAgent();
var voipMediaSession = new VoIPMediaSession();
voipMediaSession.AcceptRtpFromAny = false;
voipMediaSession.AudioExtrasSource.SetSource(AudioSourcesEnum.Silence);
SipDialerAccount sipDialerAccount = new SipDialerAccount();
int maxRetries = 5;
int retryCount = 0;
bool callResult = false;
while (retryCount < maxRetries)
{
try
{
SIPCallDescriptor callDescriptor = new SIPCallDescriptor(
username: username,
password: password,
uri: $"sip:{destination}@{domain}",
from: $"sip:{callerId}@{domain}",
to: $"sip:{destination}@{domain}",
routeSet: null,
customHeaders: null,
authUsername: null,
callDirection: SIPCallDirection.Out,
contentType: null,
content: null,
mangleIPAddress: null);
callResult = await userAgent.Call(callDescriptor, voipMediaSession, 0);
if (callResult)
{
_logger.LogInformation("Call succeeded.");
break;
}
else
{
_logger.LogWarning($"Call failed. Retrying... (Attempt {retryCount + 1} of {maxRetries})");
retryCount++;
await Task.Delay(10000); // Delay between retries
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error making call.");
break;
}
}
if (!callResult)
{
_logger.LogError("All call attempts failed.");
}
}
private static void AddConsoleLogger()
{
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug)
.WriteTo.Console()
.CreateLogger();
var factory = new SerilogLoggerFactory(logger);
SIPSorcery.LogFactory.Set(factory);
_logger = factory.CreateLogger<Program>();
}
}
This is the Serilog output:
[22:51:12 INF] SIP Get Started [22:51:12 DBG] CreateRtpSocket attempting to create and bind RTP socket(s) on [::]:0. [22:51:12 DBG] CreateBoundSocket attempting to create and bind socket(s) on [::]:0 using protocol Udp. [22:51:12 DBG] CreateBoundSocket even port required, closing socket on [::]:49667 and retrying on 49668. [22:51:12 DBG] CreateBoundSocket attempting to create and bind socket(s) on [::]:49669 using protocol Udp. [22:51:12 DBG] CreateBoundSocket successfully bound on [::]:49669, dual mode True. [22:51:12 DBG] Successfully bound RTP socket [::]:49668 (dual mode True) and control socket [::]:49669 (dual mode True). [22:51:12 DBG] RTPChannel for [::]:49668 started. [22:51:12 DBG] SIPClientUserAgent attempting to resolve atlanta2.voip.ms. [22:51:13 DBG] SIPClientUserAgent resolved atlanta2.voip.ms to udp:MY_IP:5060 in 1074.87ms. [22:51:13 DBG] UAC commencing call to sip:[email protected]:5060. [22:51:14 DBG] CreateBoundSocket attempting to create and bind socket(s) on 0.0.0.0:0 using protocol Udp. [22:51:14 DBG] CreateBoundSocket successfully bound on 0.0.0.0:57590. [22:51:14 INF] SIP UDP Channel created for udp:0.0.0.0:57590. [22:51:14 DBG] Information response 100 Trying for sip:[email protected]. [22:51:14 INF] Call attempt to sip:[email protected] received a trying response INVITE 100 Trying. [22:51:14 DBG] Response 603 Declined for sip:[email protected]. [22:51:14 WRN] Call attempt was answered with failure response INVITE 603 Declined. [22:51:14 WRN] Call failed. Retrying… (Attempt 1 of 5)
Do I missing something for the callerId ???
LeanTyl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.