- Joined
- Jul 8, 2021
- Messages
- 4
- Reaction score
- 0
3CX removed DTMF used in v18 and we wiill need use processing script in the V20 .
we can add an audio file In the processing script, that i thought that this audio was reproduced during the introducing, but it was not work like i thought
so i tried to force using a var to set the audio, but nothing too. i am not a specialist in C# and i have some customers using DTMF, it is simple example to redirect the calls (the redirecting is working), but i can not get reproduce the customer audio.
Could someone help me to set the audio and share some docs to follow and lear more about i?
using CallFlow;
using System;
using System.Threading;
using System.Threading.Tasks;
using TCX.Configuration;
using TCX.PBXAPI;
using System.Collections.Generic;
namespace dummy
{
public class UserInputIVRSample : ScriptBase<UserInputIVRSample>
{
string theFile = "Data/Ivr/Prompts/Callflows/MYAUDIO/myaudio.wav";
///<see cref="getUserInput"/>
void OnDTMFInput(char x, TaskCompletionSource<string> currentInputTaskSource, ref string theInput, Timer timer, int interdigits)
{
if(x=='#')
{
timer?.Change(Timeout.Infinite, Timeout.Infinite);
MyCall.Info($"User input is '{theFile}'");
currentInputTaskSource.TrySetResult(theInput);
}
else
{
timer?.Change(interdigits, Timeout.Infinite);
theInput += x;
}
}
Dictionary<string, string> UserInputMap=new Dictionary<string, string>
{
{"1234", "1001"},
{"2345", "1037"},
{"3456", "1033"},
{"", "103"} //NO INPUT
};
async Task<string> getUserInput(int interdigitTimeOut, int inputtimeout)
{
string theInput="";
var currentInputTaskSource = new TaskCompletionSource<string>();
var timer = new Timer((x)=>OnDTMFInput('#', currentInputTaskSource, ref theInput, null, 0), null, inputtimeout, Timeout.Infinite);
var x = (char x)=>OnDTMFInput(x, currentInputTaskSource, ref theInput, timer, interdigitTimeOut);
MyCall.OnDTMFInput+=x;
try
{
await MyCall.PlayPrompt(theFile, new [] {"PLSENTER", "PIN", "THENPRESPND"}, PlayPromptOptions.ResetBufferAtStart|PlayPromptOptions.CancelPlaybackAtFirstChar);
MyCall.Info($"prompt played{theFile}"); //
return await currentInputTaskSource.Task;
}
finally
{
timer.Dispose();
MyCall.OnDTMFInput -= x;
}
}
public override async void Start()
{
try
{
string userInput = await getUserInput(5000, 10000);
if (UserInputMap.ContainsKey(userInput))
{
string destination = UserInputMap[userInput];
MyCall.Info($"Routing to {destination}");
}
else
{
MyCall.Info("Invalid PIN entered.");
}
}
catch (Exception ex)
{
MyCall.Info($"Exception: {ex.Message}");
}
}
}
}
we can add an audio file In the processing script, that i thought that this audio was reproduced during the introducing, but it was not work like i thought
so i tried to force using a var to set the audio, but nothing too. i am not a specialist in C# and i have some customers using DTMF, it is simple example to redirect the calls (the redirecting is working), but i can not get reproduce the customer audio.
Could someone help me to set the audio and share some docs to follow and lear more about i?
using CallFlow;
using System;
using System.Threading;
using System.Threading.Tasks;
using TCX.Configuration;
using TCX.PBXAPI;
using System.Collections.Generic;
namespace dummy
{
public class UserInputIVRSample : ScriptBase<UserInputIVRSample>
{
string theFile = "Data/Ivr/Prompts/Callflows/MYAUDIO/myaudio.wav";
///<see cref="getUserInput"/>
void OnDTMFInput(char x, TaskCompletionSource<string> currentInputTaskSource, ref string theInput, Timer timer, int interdigits)
{
if(x=='#')
{
timer?.Change(Timeout.Infinite, Timeout.Infinite);
MyCall.Info($"User input is '{theFile}'");
currentInputTaskSource.TrySetResult(theInput);
}
else
{
timer?.Change(interdigits, Timeout.Infinite);
theInput += x;
}
}
Dictionary<string, string> UserInputMap=new Dictionary<string, string>
{
{"1234", "1001"},
{"2345", "1037"},
{"3456", "1033"},
{"", "103"} //NO INPUT
};
async Task<string> getUserInput(int interdigitTimeOut, int inputtimeout)
{
string theInput="";
var currentInputTaskSource = new TaskCompletionSource<string>();
var timer = new Timer((x)=>OnDTMFInput('#', currentInputTaskSource, ref theInput, null, 0), null, inputtimeout, Timeout.Infinite);
var x = (char x)=>OnDTMFInput(x, currentInputTaskSource, ref theInput, timer, interdigitTimeOut);
MyCall.OnDTMFInput+=x;
try
{
await MyCall.PlayPrompt(theFile, new [] {"PLSENTER", "PIN", "THENPRESPND"}, PlayPromptOptions.ResetBufferAtStart|PlayPromptOptions.CancelPlaybackAtFirstChar);
MyCall.Info($"prompt played{theFile}"); //
return await currentInputTaskSource.Task;
}
finally
{
timer.Dispose();
MyCall.OnDTMFInput -= x;
}
}
public override async void Start()
{
try
{
string userInput = await getUserInput(5000, 10000);
if (UserInputMap.ContainsKey(userInput))
{
string destination = UserInputMap[userInput];
MyCall.Info($"Routing to {destination}");
}
else
{
MyCall.Info("Invalid PIN entered.");
}
}
catch (Exception ex)
{
MyCall.Info($"Exception: {ex.Message}");
}
}
}
}