forked from Montesuma80/3cx-web-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makecall.cs
87 lines (83 loc) · 5.32 KB
/
makecall.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Text;
using TCX.Configuration;
using TCX.PBXAPI;
using System.Threading;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Net;
namespace WebAPI
{
public class makedirectcall
{
//Arg1 = Extension
//Arg2 = Destination
//Arg3 = Phoneart (Soft /desktop)
//if one of them is empty, send error Back
public static string dial(string args1,string args2,string args3)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("From Extension: " + args1);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("To Destination " + args2);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Phone " + args3);
Console.ResetColor();
string mod;
//using (var ev = new AutoResetEvent(false))
//using (var listener2 = new PsTypeEventListener<ActiveConnection>())
foreach (var dn in PhoneSystem.Root.GetDN().GetDisposer(x => x.Number.StartsWith(args1 == "all" ? "" : args1)))
{
foreach (var r in dn.GetRegistrarContactsEx())
{
string result = $"{r.ID}-{r.Contact}-{r.UserAgent}";
Console.WriteLine("DNReg " + result);
if (result.Contains("3CXPhone for Windows") && args3 == "Soft")
{
int cut = result.IndexOf('-');
mod = result.Substring(0, cut);
var registrarRecord = PhoneSystem.Root.GetByID<RegistrarRecord>(int.Parse(mod));
//listener2.SetTypeHandler(null, (x) => ev.Set(), null, (x) => x["devcontact"].Equals(registrarRecord.Contact), (x) => ev.WaitOne(x));
PhoneSystem.Root.MakeCall(registrarRecord, args2);
// Construct a response.
//respone the CallID
Thread.Sleep(2500);
string callid = getcallid.showcallid(args1);
return (callid);
}
else if (result.Contains("3CX") && args3 == "Web")
{
Console.WriteLine(args3);
int cut = result.IndexOf('-');
mod = result.Substring(0, cut);
var registrarRecord = PhoneSystem.Root.GetByID<RegistrarRecord>(int.Parse(mod));
//listener2.SetTypeHandler(null, (x) => ev.Set(), null, (x) => x["devcontact"].Equals(registrarRecord.Contact), (x) => ev.WaitOne(x));
PhoneSystem.Root.MakeCall(registrarRecord, args2);
Thread.Sleep(2500);
string callid = getcallid.showcallid(args1);
return (callid);
}
else if (!result.Contains("3CX") && args3 == "Desktop")
{
Console.WriteLine(args3);
int cut = result.IndexOf('-');
mod = result.Substring(0, cut);
var registrarRecord = PhoneSystem.Root.GetByID<RegistrarRecord>(int.Parse(mod));
//listener2.SetTypeHandler(null, (x) => ev.Set(), null, (x) => x["devcontact"].Equals(registrarRecord.Contact), (x) => ev.WaitOne(x));
PhoneSystem.Root.MakeCall(registrarRecord, args2);
Thread.Sleep(2500);
string callid = getcallid.showcallid(args1);
return (callid);
}
else
{
Console.WriteLine("next");
}
}
}
return ("null");
}
}
}