Beispiel #1
0
        public async Task SendWhatsappSms(int tenantId, List <string> orders, decimal subTotal, decimal deliveryFee,
                                          decimal amount, decimal tax, DateTime deliveryDateTime, int userTimeZoneOffset, string paymentMethod,
                                          string?message, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            var tenant = await _meredithDbContext.Tenants
                         .Include(item => item.User)
                         .FirstOrDefaultAsync(item => item.Id == tenantId);

            var recepients = new List <string>()
            {
                user.PhoneNumber,
                tenant.User.PhoneNumber
            };

            StringBuilder formatReader = new StringBuilder(_twilioService.GetWhatsappSmsTemplate());

            formatReader.Replace("{orders}", string.Join("\n", orders));
            formatReader.Replace("{subTotal}", subTotal.ToString());
            formatReader.Replace("{tax}", tax.ToString());
            formatReader.Replace("{deliveryFee}", deliveryFee.ToString());
            formatReader.Replace("{amount}", amount.ToString());
            formatReader.Replace("{deliveryAddress}", user.Address);
            formatReader.Replace("{name}", user.Name);
            formatReader.Replace("{phone}", user.PhoneNumber);
            formatReader.Replace("{email}", user.Email);
            formatReader.Replace("{paymentMethod}", paymentMethod);
            formatReader.Replace("{deliveryTime}", deliveryDateTime.InZone(userTimeZoneOffset, "ddd, d MMM hh:mm"));
            formatReader.Replace("{message}", !string.IsNullOrEmpty(message) ? message : "N/A");
            formatReader.Replace("{tenantName}", tenant.Name.ToUpper());
            formatReader.Replace("{tenantGooglemaps}", tenant.User.GoogleLocation);
            formatReader.Replace("{tenantPhone}", tenant.User.PhoneNumber);
            formatReader.Replace("{tenantEmail}", tenant.User.Email);

            await _twilioService.SendWhatsapp(formatReader.ToString(), recepients);
        }