Skip to content

Commit c6867d6

Browse files
authored
Merge pull request #1 from Sepand96/master
Added VoiceMail Event.
2 parents c776b4c + 32997f0 commit c6867d6

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed

NEventSocket/FreeSwitch/CustomEvents.cs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public static class Conference
77
public const string Maintainence = "conference::maintenance";
88
}
99

10+
public static class VoiceMail
11+
{
12+
public const string Maintenance = "vm::maintenance";
13+
}
14+
1015
public static class Sofia
1116
{
1217
public const string Register = "sofia::register";

NEventSocket/FreeSwitch/HeaderNames.cs

+33
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,39 @@ public static class Conference
8787

8888
public const string Action = "Action";
8989
}
90+
91+
public static class VoiceMail
92+
{
93+
public const string Action = "VM-Action";
94+
95+
public const string User = "VM-User";
96+
97+
public const string Domain = "VM-Domain";
98+
99+
public const string TotalNew = "VM-Total-New";
100+
101+
public const string TotalSaved = "VM-Total-Saved";
102+
103+
public const string TotalNewUrgent = "VM-Total-New-Urgent";
104+
105+
public const string TotalSavedUrgent = "VM-Total-Saved-Urgent";
106+
107+
public const string CallerIdName = "VM-Caller-ID-Name";
108+
109+
public const string CallerIdNumber = "VM-Caller-ID-Number";
110+
111+
public const string Folder = "VM-Folder";
112+
113+
public const string FilePath = "VM-File-Path";
114+
115+
public const string Flags = "VM-Flags";
116+
117+
public const string Uuid = "VM-UUID";
118+
119+
public const string MessageLength = "VM-Message-Len";
120+
121+
public const string Timestamp = "VM-Timestamp";
122+
}
90123
#pragma warning restore 1591
91124
}
92125
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+

2+
namespace NEventSocket.FreeSwitch
3+
{
4+
/// <summary>
5+
/// Based on actions found in:
6+
/// https://github.com/signalwire/freeswitch/blob/739e770c343db50a360f752a461da176c8a455ad/src/mod/applications/mod_voicemail/mod_voicemail.c
7+
/// </summary>
8+
public enum VoiceMailAction
9+
{
10+
MWIUpdate,
11+
FolderSummary,
12+
RemoveGreeting,
13+
ChangeGreeting,
14+
RecordGreeting,
15+
ChangePassword,
16+
RecordName,
17+
Authentication,
18+
LeaveMessage
19+
}
20+
}
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
using System;
2+
using NEventSocket.Util;
3+
4+
namespace NEventSocket.FreeSwitch
5+
{
6+
public class VoiceMailEvent : EventMessage
7+
{
8+
protected internal VoiceMailEvent(EventMessage other) : base(other)
9+
{
10+
if (other.EventName != EventName.Custom && other.Headers[HeaderNames.EventSubclass] != CustomEvents.VoiceMail.Maintenance)
11+
{
12+
throw new InvalidOperationException(
13+
"Expected event of type Custom with SubClass vm::maintainance, got {0} instead".Fmt(other.EventName));
14+
}
15+
}
16+
17+
public VoiceMailAction Action
18+
{
19+
get
20+
{
21+
if (Headers.TryGetValue(HeaderNames.VoiceMail.Action, out string headerValue))
22+
{
23+
if (Enum.TryParse(headerValue.Replace("-", string.Empty).Replace("_", string.Empty), true, out VoiceMailAction action))
24+
{
25+
return action;
26+
}
27+
throw new NotSupportedException("Unable to parse VoiceMail Action '{0}'.".Fmt(headerValue));
28+
}
29+
30+
throw new InvalidOperationException("Event did not contain an Action Header");
31+
}
32+
}
33+
34+
public string User
35+
{
36+
get
37+
{
38+
return Headers[HeaderNames.VoiceMail.User];
39+
}
40+
}
41+
42+
public string Domain
43+
{
44+
get
45+
{
46+
return Headers[HeaderNames.VoiceMail.Domain];
47+
}
48+
}
49+
50+
public string TotalNew
51+
{
52+
get
53+
{
54+
return Headers[HeaderNames.VoiceMail.TotalNew];
55+
}
56+
}
57+
58+
public string TotalSaved
59+
{
60+
get
61+
{
62+
return Headers[HeaderNames.VoiceMail.TotalSaved];
63+
}
64+
}
65+
66+
public string TotalSavedUrgent
67+
{
68+
get
69+
{
70+
return Headers[HeaderNames.VoiceMail.TotalSavedUrgent];
71+
}
72+
}
73+
74+
public string TotalNewUrgent
75+
{
76+
get
77+
{
78+
return Headers[HeaderNames.VoiceMail.TotalNewUrgent];
79+
}
80+
}
81+
82+
public string CallerIdName
83+
{
84+
get
85+
{
86+
return Headers[HeaderNames.VoiceMail.CallerIdName];
87+
}
88+
}
89+
90+
public string CallerIdNumber
91+
{
92+
get
93+
{
94+
return Headers[HeaderNames.VoiceMail.CallerIdNumber];
95+
}
96+
}
97+
98+
public string Folder
99+
{
100+
get
101+
{
102+
return Headers[HeaderNames.VoiceMail.Folder];
103+
}
104+
}
105+
106+
public string FilePath
107+
{
108+
get
109+
{
110+
return Headers[HeaderNames.VoiceMail.FilePath];
111+
}
112+
}
113+
114+
public string Flags
115+
{
116+
get
117+
{
118+
return Headers[HeaderNames.VoiceMail.Flags];
119+
}
120+
}
121+
122+
public string MessageLength
123+
{
124+
get
125+
{
126+
return Headers[HeaderNames.VoiceMail.MessageLength];
127+
}
128+
}
129+
130+
public string Uuid
131+
{
132+
get
133+
{
134+
return Headers[HeaderNames.VoiceMail.Uuid];
135+
}
136+
}
137+
138+
public string TimeStamp
139+
{
140+
get
141+
{
142+
return Headers[HeaderNames.VoiceMail.Timestamp];
143+
}
144+
}
145+
146+
public override string ToString()
147+
{
148+
return $"VoiceMailEvent: {Action} {User} {Domain} {TotalNew} {TotalSaved} {TotalSavedUrgent} {TotalNewUrgent} {CallerIdName} {CallerIdNumber} {Folder} {FilePath} {Flags} {MessageLength} {Uuid} {TimeStamp}";
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)