politely ending phone call
This commit is contained in:
parent
c6fc411dd5
commit
a537a647cd
|
|
@ -1,4 +1,7 @@
|
|||
using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.LlmContexts;
|
||||
using Microsoft.VisualBasic;
|
||||
using Twilio.Rest.Api.V2010.Account;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
|
||||
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Functions;
|
||||
|
||||
|
|
@ -20,6 +23,7 @@ public class HangupPhoneCallFn : IFunctionCallback
|
|||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
{
|
||||
var args = JsonSerializer.Deserialize<HangupPhoneCallArgs>(message.FunctionArgs);
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
var callSid = states.GetState("twilio_call_sid");
|
||||
|
||||
|
|
@ -30,14 +34,20 @@ public class HangupPhoneCallFn : IFunctionCallback
|
|||
return false;
|
||||
}
|
||||
|
||||
// Have to find the SID by the phone number
|
||||
var call = CallResource.Update(
|
||||
status: CallResource.UpdateStatusEnum.Completed,
|
||||
pathSid: callSid
|
||||
);
|
||||
message.Content = args.GoodbyeMessage;
|
||||
|
||||
message.Content = "The call has ended.";
|
||||
message.StopCompletion = true;
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(args.GoodbyeMessage.Split(' ').Length * 400);
|
||||
// Have to find the SID by the phone number
|
||||
var call = CallResource.Update(
|
||||
status: CallResource.UpdateStatusEnum.Completed,
|
||||
pathSid: callSid
|
||||
);
|
||||
|
||||
message.Content = "The call has ended.";
|
||||
message.StopCompletion = true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.LlmContexts;
|
||||
|
||||
public class HangupPhoneCallArgs
|
||||
{
|
||||
[JsonPropertyName("goodbye_message")]
|
||||
public string? GoodbyeMessage { get; set; }
|
||||
}
|
||||
|
|
@ -5,8 +5,8 @@ namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.LlmContexts;
|
|||
public class LlmContextIn
|
||||
{
|
||||
[JsonPropertyName("phone_number")]
|
||||
public string PhoneNumber { get; set; }
|
||||
public string PhoneNumber { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("initial_message")]
|
||||
public string InitialMessage { get; set; }
|
||||
public string? InitialMessage { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@
|
|||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"goodbye_message": {
|
||||
"type": "string",
|
||||
"description": "A polite closing statement for ending a conversation."
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
"required": [ "goodbye_message" ]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue