@@ -22,6 +22,7 @@ THIRD_PARTY_INCLUDES_END
2222// #pragma comment (lib, "crypt32.lib")
2323
2424DEFINE_LOG_CATEGORY (ConvaiGRPCLog);
25+ DEFINE_LOG_CATEGORY (ConvaiGRPCFeedBackLog);
2526
2627using ::service::GetResponseRequest_GetResponseConfig;
2728using ::service::TriggerConfig;
@@ -32,6 +33,9 @@ using ::service::ActionConfig_Character;
3233using ::service::GetResponseRequest_GetResponseData;
3334using ::service::FaceModel;
3435
36+ using ::service::FeedbackRequest;
37+ using ::service::FeedbackRequest_Feedback;
38+
3539using grpc::Channel;
3640using grpc::ClientAsyncResponseReader;
3741using grpc::ClientContext;
@@ -603,7 +607,13 @@ void UConvaiGRPCGetResponseProxy::OnStreamRead(bool ok)
603607 ConvaiGRPCGetResponseParams.SessionID = FString (SessionID_std.c_str ());
604608 // Broadcast the Session ID
605609 OnSessionIDReceived.ExecuteIfBound (ConvaiGRPCGetResponseParams.SessionID );
610+ }
606611
612+ std::string InteractionID_std = reply->interaction_id ();
613+ if (InteractionID_std.size ())
614+ {
615+ // Broadcast the Interaction ID
616+ OnInteractionIDReceived.ExecuteIfBound (FString (InteractionID_std.c_str ()));
607617 }
608618
609619 if (reply->has_user_query ()) // Is there transcription ready
@@ -884,4 +894,170 @@ void UConvaiGRPCGetResponseProxy::OnStreamFinish(bool ok)
884894
885895
886896 OnFinish.ExecuteIfBound ();
887- }
897+ }
898+
899+
900+
901+
902+ UConvaiGRPCSubmitFeedbackProxy* UConvaiGRPCSubmitFeedbackProxy::CreateConvaiGRPCSubmitFeedbackProxy (UObject* WorldContextObject, FString InteractionID, bool ThumbsUp, FString FeedbackText)
903+ {
904+ UConvaiGRPCSubmitFeedbackProxy* Proxy = NewObject<UConvaiGRPCSubmitFeedbackProxy>();
905+ Proxy->WorldPtr = GEngine->GetWorldFromContextObject (WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
906+ Proxy->InteractionID = InteractionID;
907+ Proxy->ThumbsUp = ThumbsUp;
908+ Proxy->FeedbackText = FeedbackText;
909+ return Proxy;
910+ }
911+
912+ void UConvaiGRPCSubmitFeedbackProxy::Activate ()
913+ {
914+ OnStreamFinishDelegate = FgRPC_Delegate::CreateUObject (this , &ThisClass::OnStreamFinish);
915+
916+ reply = std::unique_ptr<service::FeedbackResponse>(new service::FeedbackResponse ());
917+
918+ // Form Validation
919+ if (!(UConvaiFormValidation::ValidateSessionID (InteractionID)))
920+ {
921+ LogAndEcecuteFailure (" Activate" );
922+ return ;
923+ }
924+
925+ if (!WorldPtr.IsValid ())
926+ {
927+ UE_LOG (ConvaiGRPCFeedBackLog, Warning, TEXT (" WorldPtr not valid" ));
928+ LogAndEcecuteFailure (" Activate" );
929+ return ;
930+ }
931+
932+ UConvaiSubsystem* ConvaiSubsystem = UConvaiUtils::GetConvaiSubsystem (WorldPtr.Get ());
933+ if (!ConvaiSubsystem)
934+ {
935+ UE_LOG (ConvaiGRPCFeedBackLog, Warning, TEXT (" Convai Subsystem is not valid" ));
936+ LogAndEcecuteFailure (" Activate" );
937+ return ;
938+ }
939+
940+ // Create a new stub instance
941+ stub_ = ConvaiSubsystem->gRPC_Runnable ->GetNewStub ();
942+ if (!stub_)
943+ {
944+ UE_LOG (ConvaiGRPCFeedBackLog, Warning, TEXT (" Could not aquire a new stub instance" ));
945+ LogAndEcecuteFailure (" Activate" );
946+ return ;
947+ }
948+
949+ // Aquire the completion queue instance
950+ cq_ = ConvaiSubsystem->gRPC_Runnable ->GetCompletionQueue ();
951+ if (!cq_)
952+ {
953+ UE_LOG (ConvaiGRPCFeedBackLog, Warning, TEXT (" Got an invalid completion queue instance" ));
954+ LogAndEcecuteFailure (" Activate" );
955+ return ;
956+ }
957+
958+ bool Found;
959+ FString VersionName;
960+ FString EngineVersion;
961+ FString PlatformName;
962+ FString PluginEngineVersion;
963+ FString FriendlyName;
964+
965+ UConvaiUtils::GetPluginInfo (FString (" Convai" ), Found, VersionName, FriendlyName, PluginEngineVersion);
966+ UConvaiUtils::GetPlatformInfo (EngineVersion, PlatformName);
967+
968+ // Add metadata
969+ client_context.AddMetadata (" engine" , " Unreal Engine" );
970+ client_context.AddMetadata (" engine_version" , TCHAR_TO_UTF8 (*EngineVersion));
971+ client_context.AddMetadata (" platform_name" , TCHAR_TO_UTF8 (*PlatformName));
972+
973+ if (Found)
974+ {
975+ client_context.AddMetadata (" plugin_engine_version" , TCHAR_TO_UTF8 (*PluginEngineVersion));
976+ client_context.AddMetadata (" plugin_version" , TCHAR_TO_UTF8 (*VersionName));
977+ client_context.AddMetadata (" plugin_base_name" , TCHAR_TO_UTF8 (*FriendlyName));
978+ }
979+ else
980+ {
981+ client_context.AddMetadata (" plugin_engine_version" , " Unknown" );
982+ client_context.AddMetadata (" plugin_version" , " Unknown" );
983+ client_context.AddMetadata (" plugin_base_name" , " Unknown" );
984+ }
985+
986+ FeedbackRequest_Feedback* feedbackRequest_Feedback = new FeedbackRequest_Feedback ();
987+ feedbackRequest_Feedback->set_feedback_text (TCHAR_TO_UTF8 (*FeedbackText));
988+ feedbackRequest_Feedback->set_thumbs_up (ThumbsUp);
989+
990+ request.set_allocated_text_feedback (feedbackRequest_Feedback);
991+ request.set_interaction_id (TCHAR_TO_UTF8 (*InteractionID));
992+
993+
994+ stream_handler = stub_->AsyncSubmitFeedback (&client_context, request, cq_);
995+ stream_handler->Finish (reply.get (), &status, (void *)&OnStreamFinishDelegate);
996+ }
997+
998+ void UConvaiGRPCSubmitFeedbackProxy::OnStreamFinish (bool ok)
999+ {
1000+ if (!ok || !status.ok ())
1001+ {
1002+ LogAndEcecuteFailure (" OnStreamFinish" );
1003+ return ;
1004+ }
1005+
1006+ Response = FString (reply->feedback_response ().c_str ());
1007+
1008+ #if ConvaiDebugMode
1009+ UE_LOG (ConvaiGRPCFeedBackLog, Log,
1010+ TEXT (" On Stream Finish | Interaction ID : %s | Feedback Text : %s | ThumbsUp: %s" ),
1011+ *InteractionID,
1012+ *FeedbackText,
1013+ ThumbsUp? *FString (" True" ) : *FString (" False" ));
1014+ #endif
1015+
1016+
1017+ success ();
1018+ }
1019+
1020+ void UConvaiGRPCSubmitFeedbackProxy::BeginDestroy ()
1021+ {
1022+ client_context.TryCancel ();
1023+ stub_.reset ();
1024+ UE_LOG (ConvaiGRPCFeedBackLog, Log,
1025+ TEXT (" On Stream Finish | Interaction ID : %s | Feedback Text : %s | ThumbsUp: %s" ),
1026+ *InteractionID,
1027+ *FeedbackText,
1028+ ThumbsUp ? " True" : " False" );
1029+ Super::BeginDestroy ();
1030+ }
1031+
1032+ void UConvaiGRPCSubmitFeedbackProxy::LogAndEcecuteFailure (FString FuncName)
1033+ {
1034+ UE_LOG (ConvaiGRPCFeedBackLog, Warning,
1035+ TEXT (" %s: Status:%s | Debug Log:%s | Error message:%s | Error Details:%s | Error Code:%i | Interaction ID : %s | Feedback Text : %s | ThumbsUp: %s" ),
1036+ *FString (FuncName),
1037+ *FString (status.ok () ? " Ok" : " Not Ok" ),
1038+ *FString (reply->DebugString ().c_str ()),
1039+ *FString (status.error_message ().c_str ()),
1040+ *FString (status.error_details ().c_str ()),
1041+ status.error_code (),
1042+ *InteractionID,
1043+ *FeedbackText,
1044+ ThumbsUp ? " True" : " False" );
1045+
1046+ failed ();
1047+ }
1048+
1049+ void UConvaiGRPCSubmitFeedbackProxy::failed ()
1050+ {
1051+ OnFailure.Broadcast (Response);
1052+ finish ();
1053+ }
1054+
1055+ void UConvaiGRPCSubmitFeedbackProxy::success ()
1056+ {
1057+ OnSuccess.Broadcast (Response);
1058+ finish ();
1059+ }
1060+
1061+ void UConvaiGRPCSubmitFeedbackProxy::finish ()
1062+ {
1063+ }
0 commit comments