From 8820a3fce7ab90a1a067934f1a72911467a3b017 Mon Sep 17 00:00:00 2001 From: Muninn Date: Sun, 17 Nov 2024 00:22:07 +0700 Subject: [PATCH] feat: backend, confirm and sign state --- backend/service/vapi_function.go | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/backend/service/vapi_function.go b/backend/service/vapi_function.go index a4b5ed9..695140a 100644 --- a/backend/service/vapi_function.go +++ b/backend/service/vapi_function.go @@ -79,6 +79,22 @@ func (s *Service) VAPIFunctionConfirm(ctx context.Context, msg *types.VapiServer } } } + + callID := msg.Message.Call.Id + // check the call id + state, err := s.GetChatState(ctx, callID) + if err != nil { + return nil, err + } + if state.Step > 1 { + return vapiToolResponse(id, fmt.Sprintf("You are trading %s, please confirm or cancel the transaction.", state.Trade.Currency)), nil + } + + // update the state + state.Step = 2 + state.IsConfirmed = confirm + s.state.Store(callID, state) + s.log.Warn("VAPIFunction called", "confirm", confirm) if confirm { res := types.ToolResult{ToolCallID: id, Result: `Tell the user:"This is the transaction waiting for your signature. Can you authorize the AI assistant to sign for you"`} @@ -112,6 +128,23 @@ func (s *Service) VAPIFunctionSign(ctx context.Context, msg *types.VapiServerMes } } } + + callID := msg.Message.Call.Id + // check the call id + state, err := s.GetChatState(ctx, callID) + if err != nil { + return nil, err + } + if state.Step > 2 { + return vapiToolResponse(id, fmt.Sprintf("You are trading %s, please confirm or cancel the transaction.", state.Trade.Currency)), nil + } + + // update the state + state.Step = 3 + state.IsSigned = confirm + state.EIP7730 = "EIP7730 Mock Data" + s.state.Store(callID, state) + s.log.Warn("VAPIFunction called", "sign", confirm) if confirm { res := types.ToolResult{ToolCallID: id, Result: `Tell the user:"Thank you, I will sign for you to complete the transaction."`}