Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BotSharp.Abstraction.Files;
using BotSharp.Abstraction.Infrastructures;
using BotSharp.Abstraction.Repositories;
using BotSharp.Core.Infrastructures;
using BotSharp.Plugin.Twilio.Interfaces;
using BotSharp.Plugin.Twilio.Models;
Expand Down Expand Up @@ -126,9 +127,11 @@ public async Task<TwiMLResult> ReceiveCallerMessage(ConversationalVoiceRequest r
SeqNumber = request.SeqNum,
Content = messageContent,
Digits = request.Digits,
From = request.From,
From = string.Equals(request.Direction, "inbound") ? request.From : request.To,
States = ParseStates(request.States)
};
callerMessage.RequestHeaders = new KeyValuePair<string, Microsoft.Extensions.Primitives.StringValues>[Request.Headers.Count];
Request.Headers.CopyTo(callerMessage.RequestHeaders, 0);
await messageQueue.EnqueueAsync(callerMessage);

response = new VoiceResponse();
Expand Down Expand Up @@ -387,6 +390,9 @@ public TwiMLResult InitiateOutboundCall(VoiceRequest request, [Required][FromQue
$"twilio/voice/speeches/{conversationId}/intial.mp3"
}
};
string tag = $"AnsweredBy: {Request.Form["AnsweredBy"]}";
var db = _services.GetRequiredService<IBotSharpRepository>();
db.AppendConversationTags(conversationId, new List<string> { tag });
var twilio = _services.GetRequiredService<TwilioService>();
var response = twilio.ReturnNoninterruptedInstructions(instruction);
return TwiML(response);
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/BotSharp.Plugin.Twilio/Models/CallerMessage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Primitives;

namespace BotSharp.Plugin.Twilio.Models
{
public class CallerMessage
Expand All @@ -8,6 +10,7 @@ public class CallerMessage
public string Digits { get; set; }
public string From { get; set; }
public Dictionary<string, string> States { get; set; } = new();
public KeyValuePair<string, StringValues>[] RequestHeaders { get; set; }

public override string ToString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public async Task<bool> Execute(RoleDialogModel message)
var call = await CallResource.CreateAsync(
url: new Uri($"{_twilioSetting.CallbackHost}/twilio/voice/init-call?conversationId={conversationId}"),
to: new PhoneNumber(args.PhoneNumber),
from: new PhoneNumber(_twilioSetting.PhoneNumber));
from: new PhoneNumber(_twilioSetting.PhoneNumber),
machineDetection: "DetectMessageEnd");

message.Content = $"The generated phone message: {args.InitialMessage}. \r\n[Conversation ID: {conversationId}]" ?? message.Content;
message.StopCompletion = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ private async Task ProcessUserMessageAsync(CallerMessage message)
var httpContext = sp.GetRequiredService<IHttpContextAccessor>();
httpContext.HttpContext = new DefaultHttpContext();
httpContext.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());
foreach (var header in message.RequestHeaders)
{
httpContext.HttpContext.Request.Headers[header.Key] = header.Value;
}
httpContext.HttpContext.Request.Headers["X-Twilio-BotSharp"] = "LOST";

AssistantMessage reply = null;
Expand Down