Ejemplo n.º 1
0
        public async Task DoOperationAsync(RequestTutorMessage message2, IBinder binder, CancellationToken token)
        {
            if (_configuration.Search.IsDevelop)
            //if (bool.Parse(_configuration["IsDevelop"]))
            {
                _email = "*****@*****.**";
            }
            var query  = new RequestTutorAdminEmailQuery(message2.LeadId);
            var result = await _queryBus.QueryAsync(query, token);

            if (result == null)
            {
                return;
            }

            foreach (var obj in result)
            {
                var code           = _dataProtectionService.ProtectData(obj.UserId.ToString(), DateTimeOffset.UtcNow.AddDays(5));
                var identifierChat = ShortId.Generate(true, false);

                var url         = _urlBuilder.BuildChatEndpoint(code, new { utm_source = "request-tutor-admin-email" });
                var commandChat = new CreateShortUrlCommand(identifierChat, url.PathAndQuery, DateTime.UtcNow.AddDays(5));
                await _commandBus.DispatchAsync(commandChat, token);

                var whatsAppLink = new UriBuilder($"https://wa.me/{obj.UserPhone.Replace("+", string.Empty)}")
                                   .AddQuery(new
                {
                    text = $"שובץ לך מורה ל{obj.CourseName} בשם {obj.TutorName}. לשוחח עם המורה לחץ {_urlBuilder.BuildShortUrlEndpoint(identifierChat)}"
                });

                string body = whatsAppLink.ToString();

                var message = new SendGridMessage()
                {
                    Subject     = "New Tutor request",
                    HtmlContent = $"<html><body>{body.Replace(Environment.NewLine, "<br><br>")}</body></html>"
                };

                message.AddTo(_email);
                var emailProvider =
                    await binder.BindAsync <IAsyncCollector <SendGridMessage> >(new SendGridAttribute()
                {
                    ApiKey = "SendgridKey", From = "Spitball <*****@*****.**>"
                }, token);

                await emailProvider.AddAsync(message, token);

                await emailProvider.FlushAsync(token);
            }
        }
Ejemplo n.º 2
0
 public async Task RequestTutorAdminEmailQuery_Ok()
 {
     var query = new RequestTutorAdminEmailQuery(Guid.Parse("F339FFCE-7310-4C5B-B0FA-AB2E00EBA022"));
     var _     = await fixture.QueryBus.QueryAsync(query, default);
 }