From 8f225bb7bd7fafc7e9520d6938c8951ec41aee31 Mon Sep 17 00:00:00 2001 From: mmosquera Date: Thu, 26 Sep 2024 18:36:25 -0300 Subject: [PATCH] chore: change on preview url generation --- .../Services/Classes/BeplicService.cs | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/doppler-beplic/Services/Classes/BeplicService.cs b/doppler-beplic/Services/Classes/BeplicService.cs index 21b61dd..4d6720d 100644 --- a/doppler-beplic/Services/Classes/BeplicService.cs +++ b/doppler-beplic/Services/Classes/BeplicService.cs @@ -418,36 +418,45 @@ public async Task> GetTemplatesByRoom(int roomId) var result = JsonConvert.DeserializeObject>>(response.Content ?? string.Empty); var filteredResults = result?.Data?.Where(x => !string.IsNullOrEmpty(x.Status) && x.Status.Equals("approved", StringComparison.OrdinalIgnoreCase)); - Func selector = x => new TemplateResponse() + Func selector = x => { - BodyAmount = x.BodyAmount ?? 0, - BodyText = x.BodyText, - Category = x.Category, - FooterText = x.FooterText, - HeaderAmount = x.HeaderAmount ?? 0, - HeaderText = x.HeaderText, - HeaderType = x.HeaderType, - Id = x.Id, - Name = x.Name, - Language = x.Language, - ParameterHeader = x.ParameterHeader, - PublicPreviewUrl = _sdk.GetServiceFullUrl("/external-template", new Parameter[] { + var parameters = new List { Parameter.CreateParameter("bodyText", x.BodyText,ParameterType.QueryString), Parameter.CreateParameter("footerText", x.FooterText, ParameterType.QueryString), Parameter.CreateParameter("headerText", x.HeaderText, ParameterType.QueryString), Parameter.CreateParameter("botonPhone", x.BotonPhone, ParameterType.QueryString), - Parameter.CreateParameter("botonUrl", x.BotonUrl, ParameterType.QueryString), Parameter.CreateParameter("labelPhone", x.LabelPhone, ParameterType.QueryString), - Parameter.CreateParameter("labelUrl", x.LabelUrl, ParameterType.QueryString), - Parameter.CreateParameter("parameterHeader", x.ParameterHeader, ParameterType.QueryString), - Parameter.CreateParameter("parameter1Body", x.Parameter1Body, ParameterType.QueryString), - Parameter.CreateParameter("parameter2Body", x.Parameter2Body, ParameterType.QueryString), - Parameter.CreateParameter("parameter3Body", x.Parameter3Body, ParameterType.QueryString), Parameter.CreateParameter("quickReply1", x.QuickReply1, ParameterType.QueryString), Parameter.CreateParameter("quickReply2", x.QuickReply2, ParameterType.QueryString), Parameter.CreateParameter("quickReply3", x.QuickReply3, ParameterType.QueryString), - Parameter.CreateParameter("headerType", x.HeaderType, ParameterType.QueryString), - Parameter.CreateParameter("fileId", x.FieldId, ParameterType.QueryString)}) + Parameter.CreateParameter("headerType", x.HeaderType, ParameterType.QueryString) + }; + + if (!string.IsNullOrEmpty(x.HeaderType) && !x.HeaderType.Equals("TEXT", StringComparison.OrdinalIgnoreCase)) + { + parameters.Add(Parameter.CreateParameter("parameterHeader", x.ParameterHeader, ParameterType.QueryString)); + } + + if (x.FieldId != null) + { + parameters.Add(Parameter.CreateParameter("fileId", x.FieldId, ParameterType.QueryString)); + } + + return new TemplateResponse() + { + BodyAmount = x.BodyAmount ?? 0, + BodyText = x.BodyText, + Category = x.Category, + FooterText = x.FooterText, + HeaderAmount = x.HeaderAmount ?? 0, + HeaderText = x.HeaderText, + HeaderType = x.HeaderType, + Id = x.Id, + Name = x.Name, + Language = x.Language, + ParameterHeader = x.ParameterHeader, + PublicPreviewUrl = _sdk.GetServiceFullUrl("/external-template", parameters.ToArray()) + }; }; return filteredResults?.Select(selector) ?? Enumerable.Empty();