Merge pull request #1038 from Lessen-LLC/Development
Adding inbound call recording.
This commit is contained in:
commit
a3aabe29aa
|
|
@ -107,6 +107,12 @@ public class TwilioInboundController : TwilioController
|
|||
response.Redirect(new Uri($"{_settings.CallbackHost}/twilio/voice/reply/{seqNum}?agent-id={request.AgentId}&conversation-id={request.ConversationId}&{twilio.GenerateStatesParameter(request.States)}"), HttpMethod.Post);
|
||||
}
|
||||
}
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1500);
|
||||
await twilio.StartRecording(request.CallSid, request.AgentId, request.ConversationId);
|
||||
});
|
||||
}
|
||||
|
||||
await HookEmitter.Emit<ITwilioSessionHook>(_services, async hook =>
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ public class TwilioRecordController : TwilioController
|
|||
// recording completed
|
||||
await HookEmitter.Emit<ITwilioCallStatusHook>(_services, x => x.OnRecordingCompleted(request));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError($"Unknown record status: {request.CallStatus}, {request.CallSid}");
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ public class TwilioVoiceController : TwilioController
|
|||
|
||||
var reply = await sessionManager.GetAssistantReplyAsync(request.ConversationId, request.SeqNum);
|
||||
VoiceResponse response;
|
||||
|
||||
|
||||
if (request.AIResponseWaitTime > 10)
|
||||
{
|
||||
// Wait AI Response Timeout
|
||||
|
|
@ -381,19 +381,23 @@ public class TwilioVoiceController : TwilioController
|
|||
else if (request.CallStatus == "canceled")
|
||||
{
|
||||
await HookEmitter.Emit<ITwilioCallStatusHook>(_services,
|
||||
async hook =>
|
||||
{
|
||||
if (hook.IsMatch(request)) await hook.OnCallCanceledStatus(request);
|
||||
async hook =>
|
||||
{
|
||||
if (hook.IsMatch(request)) await hook.OnCallCanceledStatus(request);
|
||||
});
|
||||
}
|
||||
else if (request.CallStatus == "failed")
|
||||
{
|
||||
await HookEmitter.Emit<ITwilioCallStatusHook>(_services,
|
||||
async hook =>
|
||||
{
|
||||
if (hook.IsMatch(request)) await hook.OnCallFailedStatus(request);
|
||||
async hook =>
|
||||
{
|
||||
if (hook.IsMatch(request)) await hook.OnCallFailedStatus(request);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError($"Unknown call status: {request.CallStatus}, {request.CallSid}");
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ using BotSharp.Core.Infrastructures;
|
|||
using BotSharp.Plugin.Twilio.Interfaces;
|
||||
using BotSharp.Plugin.Twilio.Models;
|
||||
using Twilio.Jwt.AccessToken;
|
||||
using Twilio.Rest.Api.V2010.Account.Call;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
using Token = Twilio.Jwt.AccessToken.Token;
|
||||
|
||||
namespace BotSharp.Plugin.Twilio.Services;
|
||||
|
|
@ -122,6 +124,22 @@ public class TwilioService
|
|||
return response;
|
||||
}
|
||||
|
||||
public async Task StartRecording(string callSid, string agentId, string conversationId)
|
||||
{
|
||||
if (_settings.RecordingEnabled)
|
||||
{
|
||||
// https://help.twilio.com/articles/360010317333-Recording-Incoming-Twilio-Voice-Calls
|
||||
var recordStatusUrl = $"{_settings.CallbackHost}/twilio/record/status?agent-id={agentId}&conversation-id={conversationId}";
|
||||
var recording = await RecordingResource.CreateAsync(pathCallSid: callSid,
|
||||
recordingStatusCallback: new Uri(recordStatusUrl),
|
||||
trim: "trim-silence",
|
||||
recordingChannels: "dual",
|
||||
recordingTrack: "both");
|
||||
|
||||
_logger.LogInformation($"Recording started: {recording.CallSid} {recording.Sid}");
|
||||
}
|
||||
}
|
||||
|
||||
public VoiceResponse HangUp(string speechPath)
|
||||
{
|
||||
var response = new VoiceResponse();
|
||||
|
|
|
|||
Loading…
Reference in a new issue