I use the C # /. NET library to implement the Asterisk RESTful Interface (ARI) to create a conferencing application.
So far, the application works as follows:
- The user calls the number
- Application response
- The application starts voice recognition
- The application asks for a name and records audio
- The application adds the user to the conference
Requirements:
I need to add some authorization to the above process before the user is added to the conference. I need to implement a request for PIN functionality , create a PIN design, and if the caller enters the correct PIN, add the caller to the correct conference call.
Code:
The conference
public Conference( AriClient c, Guid id, string name)
{
_client = c;
Id = id;
ConferenceName = name;
State = ConferenceState.Destroyed;
c.OnChannelDtmfReceivedEvent += c_OnChannelDtmfReceivedEvent;
c.OnBridgeCreatedEvent += c_OnBridgeCreatedEvent;
c.OnChannelEnteredBridgeEvent += c_OnChannelEnteredBridgeEvent;
c.OnBridgeDestroyedEvent += c_OnBridgeDestroyedEvent;
c.OnChannelLeftBridgeEvent += c_OnChannelLeftBridgeEvent;
c.OnRecordingFinishedEvent += c_OnRecordingFinishedEvent;
c.OnChannelTalkingStartedEvent += c_OnChannelTalkingStartedEvent;
c.OnChannelTalkingFinishedEvent += c_OnChannelTalkingFinishedEvent;
Debug.Print("Added Conference {0}", ConferenceName);
}
OnChannelEnteredBridgeEvent:
private void c_OnChannelEnteredBridgeEvent(object sender, ChannelEnteredBridgeEvent e)
{
ConferenceUser confUser = ConferenceUsers.SingleOrDefault(x => x.Channel.Id == e.Channel.Id);
if (confUser == null) return;
confUser.State = ConferenceUserState.InConf;
if (ConferenceUsers.Count(x => x.State == ConferenceUserState.InConf) > 1)
{
_client.Bridges.StopMoh(Confbridge.Id);
State = ConferenceState.Ready;
_client.Bridges.Play(Confbridge.Id, "recording:" + confUser.CurrentRecodingId, "en", 0, 0, Guid.NewGuid().ToString());
_client.Bridges.Play(Confbridge.Id, "sound:conf-hasjoin", "en", 0, 0, Guid.NewGuid().ToString());
}
else
{
_client.Channels.Play(e.Channel.Id, "sound:conf-onlyperson", "en", 0, 0, Guid.NewGuid().ToString());
}
}
StartConference:
public bool StartConference()
{
Debug.Print("Requesting new bridge {0} for {1}", Id, ConferenceName);
Bridge bridge = _client.Bridges.Create("mixing", Id.ToString(), ConferenceName);
if (bridge == null)
{
return false;
}
Debug.Print("Subscribing to events on bridge {0} for {1}", Id, ConferenceName);
_client.Applications.Subscribe(AppConfig.AppName, "bridge:" + bridge.Id);
_client.Bridges.StartMoh(bridge.Id, "default");
State = ConferenceState.ReadyWaiting;
Confbridge = bridge;
State = ConferenceState.Ready;
return true;
}
AddUser:
public bool AddUser(Channel c)
{
if (State == ConferenceState.Destroying)
return false;
if (State == ConferenceState.Destroyed)
{
if (!StartConference())
return false;
}
if (State < ConferenceState.Ready) return false;
_client.Channels.Answer(c.Id);
_client.Channels.SetChannelVar(c.Id, "TALK_DETECT(set)", "");
ConferenceUsers.Add(new ConferenceUser(this, c, _client, ConferenceUserType.Normal));
return true;
}
Question:
How can I raise / raise the “ask pin number” event in the application and capture the entered DTMF digits into a variable?
Is it possible to do this only in my C # ARI application, or do I need to mess with .conf files on an Asterisk server?
My preferred way is to implement it in my C # ARI application, as this will give me more control over the conferences.