Skip to content

Commit 1468c01

Browse files
author
Haiping Chen
committed
Remove call_sid from function util-twilio-hangup_phone_call
1 parent 20563d2 commit 1468c01

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

src/Infrastructure/BotSharp.Core/Realtime/RealtimeHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ await completer.Connect(conn,
139139

140140
if (!string.IsNullOrEmpty(message.Content))
141141
{
142-
await hook.OnMessageReceived(message);
142+
await hook.OnResponseGenerated(message);
143143
}
144144
}
145145
}

src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioStreamController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private async Task InitConversation(ConversationalVoiceRequest request)
9393
Id = request.CallSid,
9494
AgentId = _settings.AgentId,
9595
Channel = ConversationChannel.Phone,
96+
ChannelId = request.CallSid,
9697
Title = $"Phone call from {request.From}",
9798
Tags = [],
9899
};
@@ -103,7 +104,8 @@ private async Task InitConversation(ConversationalVoiceRequest request)
103104
var states = new List<MessageState>
104105
{
105106
new("channel", ConversationChannel.Phone),
106-
new("calling_phone", request.From)
107+
new("calling_phone", request.From),
108+
new("twilio_call_sid", request.CallSid),
107109
};
108110

109111
convService.SetConversationId(conversation.Id, states);

src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.LlmContexts;
21
using Twilio.Rest.Api.V2010.Account;
32

43
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Functions;
@@ -21,14 +20,24 @@ public HangupPhoneCallFn(
2120

2221
public async Task<bool> Execute(RoleDialogModel message)
2322
{
24-
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
23+
var states = _services.GetRequiredService<IConversationStateService>();
24+
var callSid = states.GetState("twilio_call_sid");
25+
26+
if (string.IsNullOrEmpty(callSid))
27+
{
28+
message.Content = "The call has not been initiated.";
29+
_logger.LogError(message.Content);
30+
return false;
31+
}
32+
2533
// Have to find the SID by the phone number
2634
var call = CallResource.Update(
2735
status: CallResource.UpdateStatusEnum.Completed,
28-
pathSid: args.CallSid
36+
pathSid: callSid
2937
);
3038

3139
message.Content = "The call has ended.";
40+
message.StopCompletion = true;
3241

3342
return true;
3443
}

src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private async Task ForkConversation(LlmContextIn args,
105105

106106
convStorage.Append(newConversationId, new List<RoleDialogModel>
107107
{
108-
new RoleDialogModel(AgentRole.User, $"[Calling Phone To: {resource.ToFormatted}, Call SID: {resource.Sid}.]")
108+
new RoleDialogModel(AgentRole.User, "Hi")
109109
{
110110
CurrentAgentId = entryAgentId
111111
},

src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/LlmContexts/LlmContextIn.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@ public class LlmContextIn
99

1010
[JsonPropertyName("initial_message")]
1111
public string InitialMessage { get; set; }
12-
13-
[JsonPropertyName("call_sid")]
14-
public string CallSid { get; set; }
1512
}

src/Plugins/BotSharp.Plugin.Twilio/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-twilio-hangup_phone_call.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
"parameters": {
66
"type": "object",
77
"properties": {
8-
"call_sid": {
9-
"type": "string",
10-
"description": "The unique string SID that we created to identify this Call resource."
11-
}
128
},
13-
"required": [ "call_sid" ]
9+
"required": []
1410
}
1511
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
** Please call util-twilio-outbound_phone_call if user wants to make an outbound call.
2-
** For outbound calls, phone number format is "XXX-XXX-XXXX".
1+
** Please call util-twilio-outbound_phone_call if user wants to make an outbound call.

0 commit comments

Comments
 (0)