private void CheckClash(Dtmf option) { if (GotoMenuOptions.ContainsKey(option) || ReturnOptions.ContainsKey(option)) { throw new BuilderException("Option '" + option + "' already defined"); } }
/// <summary> /// Constructs an action that plays the DTMF tones passed with /// the specified individual tone duration to the current call of an /// executing dial plan. /// </summary> /// <param name="dtmfDigits">The DTMF digits.</param> /// <param name="toneDuration">The tone duration.</param> /// <remarks> /// <note> /// The actual tone duration used will be adjusted so that it falls /// within the switch limits of <see cref="Switch.MinDtmfDuration "/>..<see cref="Switch.MaxDtmfDuration" />. /// </note> /// </remarks> public PlayDtmfAction(string dtmfDigits, TimeSpan toneDuration) { if (toneDuration < Switch.MinDtmfDuration) { toneDuration = Switch.MinDtmfDuration; } else if (toneDuration > Switch.MaxDtmfDuration) { toneDuration = Switch.MaxDtmfDuration; } this.dtmfDigits = Dtmf.Validate(dtmfDigits); this.toneDuration = toneDuration; }
public string AsString(Dtmf digit) { var intValue = (int)digit; switch (digit) { case Dtmf.Asterisk: return("*"); case Dtmf.Hash: return("#"); default: return(intValue.ToString(CultureInfo.InvariantCulture)); } }
/// <summary> /// Plays an audio source until it is finished or until one of a set of DTMF /// digits is pressed or until <see cref="Break" /> or <see cref="BreakAll" /> /// is called. /// </summary> /// <param name="source">The audio source.</param> /// <param name="stopDtmf">The set of DTMF digits that will stop the operation (<see cref="Dtmf" />).</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="source" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="stopDtmf"/> includes an invalid DTMF digit.</exception> public void PlayAudio(AudioSource source, string stopDtmf) { if (source == null) { throw new ArgumentNullException("source"); } if (stopDtmf != null) { Dtmf.Validate(stopDtmf); } ActionRenderingContext.Execute(new PlayAudioAction(CallID, source) { StopDtmf = stopDtmf }); }
/// <summary> /// Called by FreeSWITCH when one of the bound events is raised. /// </summary> /// <param name="args">The event arguments.</param> /// <returns>The event results as an XML document.</returns> private static string OnSwitchXmlSearchEvent(SwitchXmlSearchBinding.XmlBindingArgs args) { string result = null; try { switch (args.Section.ToLower()) { case "directory": { if (userDirectoryEvent == null) { break; } var switchEvent = new SwitchEvent(args.Parameters); var action = switchEvent.Headers.Get("action", string.Empty).ToLower(); if (action != "sip_auth") { return(FsConfigNotFound.Xml); // Ignore non-user directory operations } var directoryArgs = new UserDirectoryEventArgs(new SwitchEvent(args.Parameters)); userDirectoryEvent(null, directoryArgs); if (directoryArgs.Handled) { if (directoryArgs.Password == null) { directoryArgs.Password = string.Empty; } if (directoryArgs.AccessDenied) { // $hack(jeff.lill): // // There's doesn't appear to be a clean way to tell the switch that the user // is valid but that access should be denied and no additional lookup should // be performed by other modules. I'm going to handle this by setting the // password to guid. directoryArgs.Password = Guid.NewGuid().ToString("N"); } // Validate and set the common parameters/variables. try { Dtmf.ValidateNumeric(directoryArgs.VoiceMailPassword, 0, int.MaxValue, true); } catch (Exception e) { SysLog.LogWarning("UserDirectoryEvent handler ignored [VoiceMailPassword]: {0}", e.Message); } try { Dtmf.ValidateNumeric(directoryArgs.EffectiveCallerIDNumber, 0, 11, true); } catch (Exception e) { SysLog.LogWarning("UserDirectoryEvent handler ignored [EffectiveCallerIDNumber]: {0}", e.Message); } try { Dtmf.ValidateNumeric(directoryArgs.OutboundCallerIDNumber, 0, 11, true); } catch (Exception e) { SysLog.LogWarning("UserDirectoryEvent handler ignored [OutboundCallerIDNumber]: {0}", e.Message); } if (directoryArgs.VoiceMailPassword != null) { directoryArgs.Parameters["vm-password"] = directoryArgs.VoiceMailPassword; } if (directoryArgs.CallingRights != CallingRight.None) { var sb = new StringBuilder(); if ((directoryArgs.CallingRights & CallingRight.Local) != 0) { sb.Append("local"); } if ((directoryArgs.CallingRights & CallingRight.Domestic) != 0) { if (sb.Length > 0) { sb.Append(','); } sb.Append("domestic"); } if ((directoryArgs.CallingRights & CallingRight.International) != 0) { if (sb.Length > 0) { sb.Append(','); } sb.Append("international"); } directoryArgs.Variables["toll_allow"] = sb.ToString(); } if (directoryArgs.AccountCode != null) { directoryArgs.Variables["accountcode"] = directoryArgs.AccountCode; } if (directoryArgs.CallerContext != null) { directoryArgs.Variables["user_context"] = directoryArgs.CallerContext; } if (directoryArgs.EffectiveCallerIDName != null) { directoryArgs.Variables["effective_caller_id_name"] = directoryArgs.EffectiveCallerIDName; } if (directoryArgs.EffectiveCallerIDNumber != null) { directoryArgs.Variables["effective_caller_id_number"] = directoryArgs.EffectiveCallerIDNumber; } if (directoryArgs.OutboundCallerIDName != null) { directoryArgs.Variables["outbound_caller_id_name"] = directoryArgs.OutboundCallerIDName; } if (directoryArgs.OutboundCallerIDNumber != null) { directoryArgs.Variables["outbound_caller_id_number"] = directoryArgs.OutboundCallerIDNumber; } if (directoryArgs.CallGroup != null) { directoryArgs.Variables["callgroup"] = directoryArgs.CallGroup; } result = new FsConfigDirectory(directoryArgs.Domain, directoryArgs.UserID, directoryArgs.Password, directoryArgs.Parameters, directoryArgs.Variables).ToXml(); Debug.WriteLine(result); // $todo(jeff.lill): Delete this } } break; case "dialplan": { if (dialPlanEvent == null) { break; } var dialPlanArgs = new DialPlanEventArgs(new SwitchEvent(args.Parameters)); dialPlanEvent(null, dialPlanArgs); if (dialPlanArgs.Handled) { if (dialPlanArgs.Context == null) { throw new ArgumentException("DialPlanEvent handler returned [Context=null]."); } var renderContext = new ActionRenderingContext(true); foreach (var action in dialPlanArgs.Actions) { action.Render(renderContext); } result = new FsConfigDialPlan(dialPlanArgs.Context, renderContext.Actions).ToXml(); } } break; default: result = null; break; } } catch (Exception e) { SysLog.LogException(e); } return(result ?? FsConfigNotFound.Xml); }
public void OnEventReceived(EslMessage eslMessage) { var eslEvent = new EslEvent(eslMessage); var eventName = eslEvent.EventName; var eventType = Enumm.Parse <EslEventType>(eventName); switch (eventType) { case EslEventType.BACKGROUND_JOB: var backgroundJob = new BackgroundJob(eslMessage); eslEvent = backgroundJob; break; case EslEventType.CALL_UPDATE: var callUpdate = new CallUpdate(eslMessage); eslEvent = callUpdate; break; case EslEventType.CHANNEL_BRIDGE: var channelBridge = new ChannelBridge(eslMessage); eslEvent = channelBridge; break; case EslEventType.CHANNEL_HANGUP: case EslEventType.CHANNEL_HANGUP_COMPLETE: var channelHangup = new ChannelHangup(eslMessage); eslEvent = channelHangup; break; case EslEventType.CHANNEL_PROGRESS: var channelProgress = new ChannelProgress(eslMessage); eslEvent = channelProgress; break; case EslEventType.CHANNEL_PROGRESS_MEDIA: var channelProgressMedia = new ChannelProgressMedia(eslMessage); eslEvent = channelProgressMedia; break; case EslEventType.CHANNEL_EXECUTE: var channelExecute = new ChannelExecute(eslMessage); eslEvent = channelExecute; break; case EslEventType.CHANNEL_EXECUTE_COMPLETE: var channelExecuteComplete = new ChannelExecuteComplete(eslMessage); eslEvent = channelExecuteComplete; break; case EslEventType.CHANNEL_UNBRIDGE: var channelUnbridge = new ChannelUnbridge(eslMessage); eslEvent = channelUnbridge; break; case EslEventType.SESSION_HEARTBEAT: var sessionHeartbeat = new SessionHeartbeat(eslMessage); eslEvent = sessionHeartbeat; break; case EslEventType.DTMF: var dtmf = new Dtmf(eslMessage); eslEvent = dtmf; break; case EslEventType.RECORD_STOP: var recordStop = new RecordStop(eslMessage); eslEvent = recordStop; break; case EslEventType.CUSTOM: var custom = new Custom(eslMessage); eslEvent = custom; break; case EslEventType.CHANNEL_STATE: var channelState = new ChannelStateEvent(eslMessage); eslEvent = channelState; break; case EslEventType.CHANNEL_ANSWER: eslEvent = new EslEvent(eslMessage); break; case EslEventType.CHANNEL_ORIGINATE: eslEvent = new EslEvent(eslMessage); break; case EslEventType.CHANNEL_PARK: var channelPark = new ChannelPark(eslMessage); eslEvent = channelPark; break; case EslEventType.CHANNEL_UNPARK: eslEvent = new EslEvent(eslMessage); break; default: OnUnhandledEvents(new EslEvent(eslMessage)); break; } HandleEvents(eslEvent, eventType); }
/// <summary> /// Constructs an action that plays the DTMF tones passed with /// the default individual tone duration of <see cref="Switch.MinDtmfDuration" /> /// to a specific call. /// </summary> /// <param name="callID">The target call ID.</param> /// <param name="dtmfDigits">The DTMF digits.</param> public PlayDtmfAction(Guid callID, string dtmfDigits) { this.CallID = callID; this.dtmfDigits = Dtmf.Validate(dtmfDigits); this.toneDuration = Switch.MinDtmfDuration; }
/// <summary> /// Constructs an action that plays the DTMF tones passed with /// the default individual tone duration of <see cref="Switch.MinDtmfDuration" /> /// to the current call of an executing dial plan. /// </summary> /// <param name="dtmfDigits">The DTMF digits.</param> public PlayDtmfAction(string dtmfDigits) { this.dtmfDigits = Dtmf.Validate(dtmfDigits); this.toneDuration = Switch.MinDtmfDuration; }
public IMenu AddTriggerPieOption(Dtmf option, string result) { CheckClash(option); ReturnOptions[option] = result; return(this); }
public IMenu AddGotoMenuOption(Dtmf option, string targetMenuId, IDictionary <string, string> cookies = null) { CheckClash(option); GotoMenuOptions[option] = new Tuple <string, IDictionary <string, string> >(targetMenuId, cookies); return(this); }
public MenuOption(Dtmf dtmf) { _dtmf = dtmf; _input = null; }
public IMenu AddTriggerPieOption(Dtmf option, string result) { return(AddTriggerPieOption((MenuOption)option, result)); }
public IMenu AddGotoMenuOption(Dtmf option, string targetMenuId, IDictionary <string, string> cookies = null) { return(AddGotoMenuOption((MenuOption)option, targetMenuId, cookies)); }