PhoneToolMX/PhoneToolMX/Services/AsteriskManager.cs
2023-10-21 13:46:56 -07:00

37 lines
1.3 KiB
C#

using System.Collections;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
using AsterNET.Manager;
namespace PhoneToolMX.Services
{
public class AsteriskManager : IAsteriskManager
{
private IConfigurationSection amiConf;
private ManagerConnection conn;
public AsteriskManager(IConfiguration config)
{
amiConf = config.GetRequiredSection("ami");
conn = new ManagerConnection(amiConf["host"],
int.Parse(amiConf["port"]),
amiConf["username"],
amiConf["secret"]);
conn.Login();
}
/// <summary>
/// Sends a <c>polycom-check-cfg</c> notification to the requested PJSIP endpoint.
/// </summary>
/// <param name="endpoint">The PJSIP endpoint to notify, without the <c>PJSIP/</c> prefix.</param>
/// <exception cref="BadResponseException">If the request fails, this exception will be thrown.</exception>
public async Task SendNotifyAsync(string endpoint)
{
var response = await conn.SendActionAsync(new PJSIPNotifyAction(endpoint, "polycom-check-cfg"));
if (!response.IsSuccess()) {
throw new BadResponseException(response.Message);
}
}
}
}