Skip to content

Commit cd8c633

Browse files
authored
Merge pull request #186 from sj-distributor/enhance-order-inf-setting
Enhance order info setting
2 parents 3df7e1f + c644e31 commit cd8c633

File tree

8 files changed

+37
-3
lines changed

8 files changed

+37
-3
lines changed

src/SmartTalk.Core/Constants/OpenAiToolConstants.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public static class OpenAiToolConstants
1515
public const string CheckOrderStatus = "check_order_status";
1616
public const string RequestOrderDelivery = "request_order_delivery";
1717
public const string ConfirmCustomerInformation = "confirm_customer_name_phone";
18+
public const string ConfirmPickupTime = "confirm_pickup_time";
1819
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table `phone_order_record` add column `comments` varchar(1024) null;

src/SmartTalk.Core/Domain/PhoneOrder/PhoneOrderRecord.cs

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class PhoneOrderRecord : IEntity
6060
[Column("customer_name"), StringLength(50)]
6161
public string CustomerName { get; set; }
6262

63+
[Column("comments")]
64+
public string Comments { get; set; }
65+
6366
[NotMapped]
6467
public UserAccount UserAccount { get; set; }
6568

src/SmartTalk.Core/Services/AiSpeechAssistant/AiSpeechAssistantProcessJobService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public async Task RecordAiSpeechAssistantCallAsync(AiSpeechAssistantStreamContex
6363
CreatedDate = callResource.StartTime ?? DateTimeOffset.Now,
6464
OrderStatus = PhoneOrderOrderStatus.Pending,
6565
CustomerName = context.UserInfo.UserName,
66-
PhoneNumber = context.UserInfo.PhoneNumber
66+
PhoneNumber = context.UserInfo.PhoneNumber,
67+
Comments = context.OrderItems.Comments
6768
};
6869

6970
await _phoneOrderDataProvider.AddPhoneOrderRecordsAsync([record], cancellationToken: cancellationToken).ConfigureAwait(false);

src/SmartTalk.Core/Services/AiSpeechAssistant/AiSpeechAssistantService.cs

+23
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ private async Task SendToTwilioAsync(WebSocket twilioWebSocket, WebSocket openAi
374374
case OpenAiToolConstants.ConfirmCustomerInformation:
375375
await ProcessRecordCustomerInformationAsync(openAiWebSocket, context, outputElement, cancellationToken).ConfigureAwait(false);
376376
break;
377+
378+
case OpenAiToolConstants.ConfirmPickupTime:
379+
await ProcessRecordOrderPickupTimeAsync(openAiWebSocket, context, outputElement, cancellationToken).ConfigureAwait(false);
380+
break;
377381

378382
case OpenAiToolConstants.Hangup:
379383
await ProcessHangupAsync(openAiWebSocket, context, outputElement, cancellationToken).ConfigureAwait(false);
@@ -451,6 +455,25 @@ private async Task ProcessRecordCustomerInformationAsync(WebSocket openAiWebSock
451455
await SendToWebSocketAsync(openAiWebSocket, recordSuccess);
452456
await SendToWebSocketAsync(openAiWebSocket, new { type = "response.create" });
453457
}
458+
459+
private async Task ProcessRecordOrderPickupTimeAsync(WebSocket openAiWebSocket, AiSpeechAssistantStreamContextDto context, JsonElement jsonDocument, CancellationToken cancellationToken)
460+
{
461+
var recordSuccess = new
462+
{
463+
type = "conversation.item.create",
464+
item = new
465+
{
466+
type = "function_call_output",
467+
call_id = jsonDocument.GetProperty("call_id").GetString(),
468+
output = "Record the time when the customer pickup the order."
469+
}
470+
};
471+
472+
context.OrderItems.Comments = JsonConvert.DeserializeObject<AiSpeechAssistantOrderDto>(jsonDocument.GetProperty("arguments").ToString())?.Comments ?? string.Empty;
473+
474+
await SendToWebSocketAsync(openAiWebSocket, recordSuccess);
475+
await SendToWebSocketAsync(openAiWebSocket, new { type = "response.create" });
476+
}
454477

455478
private async Task ProcessHangupAsync(WebSocket openAiWebSocket, AiSpeechAssistantStreamContextDto context, JsonElement jsonDocument, CancellationToken cancellationToken)
456479
{

src/SmartTalk.Core/Services/PhoneOrder/PhoneOrderService.OrderItem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public async Task<PlaceOrderAndModifyItemResponse> PlaceOrderAndModifyItemsAsync
6060
var request = new PlaceOrderToEasyPosRequestDto
6161
{
6262
Type = 1,
63-
IsTaxFree = true,
64-
Notes = string.Empty,
63+
IsTaxFree = false,
64+
Notes = record.Comments,
6565
OrderItems = orderItems.Select(x => new PhoneCallOrderItem
6666
{
6767
ProductId = x.ProductId ?? GetMenuItemByName(menuItems, x.FoodName)?.ProductId ?? 0,

src/SmartTalk.Messages/Dto/AiSpeechAssistant/AiSpeechAssistantStreamContxtDto.cs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class AiSpeechAssistantUserInfoDto
5353

5454
public class AiSpeechAssistantOrderDto
5555
{
56+
[JsonProperty("comments")]
57+
public string Comments { get; set; }
58+
5659
[JsonProperty("order_items")]
5760
public List<AiSpeechAssistantOrderItemDto> Order { get; set; }
5861
}

src/SmartTalk.Messages/Dto/PhoneOrder/PhoneOrderRecordDto.cs

+2
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public class PhoneOrderRecordDto
3232
public string PhoneNumber { get; set; }
3333

3434
public string CustomerName { get; set; }
35+
36+
public string Comments { get; set; }
3537
}

0 commit comments

Comments
 (0)