Created
March 14, 2023 02:39
-
-
Save agrgic16/6e6a876dd94b72d7f3b0da3f9bd4984c to your computer and use it in GitHub Desktop.
Override the znode WebStoreCaseRequestService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Znode.Engine.Api.Models; | |
using Znode.Engine.ERPConnector.Model.ChatGPTConnector; | |
using Znode.Engine.Services; | |
using Znode.Libraries.ECommerce.Utilities; | |
using Znode.Libraries.Framework.Business; | |
using Znode.Libraries.Observer; | |
namespace Znode.Api.Custom | |
{ | |
public class CustomWebStoreCaseRequestService : WebStoreCaseRequestService, IWebStoreCaseRequestService | |
{ | |
public CustomWebStoreCaseRequestService() { } | |
public override WebStoreCaseRequestModel CreateContactUs(WebStoreCaseRequestModel caseRequestModel) | |
{ | |
string originalFeedback = caseRequestModel.Description.Replace("Comments: ", "Original Feedback: "); | |
string feedbackToClassify = originalFeedback.Substring(0, originalFeedback.IndexOf("<br/>")); | |
var ChatGPTIntegration = new ERPInitializer<string>(feedbackToClassify, "ClassifyFeedback"); | |
var response = (ClassifiedFeedback)ChatGPTIntegration.Result; | |
if (response.Sentiment.Trim().ToLower() == "positive") | |
{ | |
return base.CreateContactUs(caseRequestModel); | |
} | |
response.Emails.ForEach(departmentEmail => { | |
string toEmail = "admin@gcgclient.app"; | |
string department = departmentEmail.Department.Trim().ToLower(); | |
string aiEmailBody = departmentEmail.EmailBody.Trim(); | |
string emailBody = $"{aiEmailBody}\r\n\r\n{originalFeedback}"; | |
if (department == "customer service") | |
{ | |
toEmail = "customerservice@gcgclient.app"; | |
} else if (department == "it") | |
{ | |
toEmail = "helpdesk@gcgclient.app"; | |
} else if (department == "marketing") | |
{ | |
toEmail = "marketing@gcgclient.app"; | |
} | |
ZnodeEmail.SendEmail(toEmail, "admin@gcgclient.app", "Negative Ecommerce Feedback", emailBody); | |
ZnodeLogging.LogMessage($"SendTo: {toEmail}\r\n\r\nEmail Body: {emailBody}", "WebstoreCaseRequest", System.Diagnostics.TraceLevel.Info); | |
}); | |
ZnodeLogging.LogMessage(ChatGPTIntegration.Result.ToString(), "WebstoreCaseRequest", System.Diagnostics.TraceLevel.Info); | |
return base.CreateContactUs(caseRequestModel); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment