public async Task <IReadOnlyCollection <IPostingService> > GetServices(Publication publication) { var categoryId = publication.CategoryId; var telegramChannels = await _socialRepository.GetTelegramChannels(categoryId); var facebookPages = await _socialRepository.GetFacebookPages(categoryId); var twitterAccounts = await _socialRepository.GetTwitterAccounts(); var slackApplications = await _socialRepository.GetSlackApplications(); var services = new List <IPostingService>(); foreach (var telegramChannel in telegramChannels) { services.Add(_factory.CreateTelegramService( telegramChannel.Token, telegramChannel.Name)); } foreach (var facebookPage in facebookPages) { services.Add(_factory.CreateFacebookService( facebookPage.Token, facebookPage.Name)); } foreach (var twitterAccount in twitterAccounts) { services.Add(_factory.CreateTwitterService( twitterAccount.ConsumerKey, twitterAccount.ConsumerSecret, twitterAccount.AccessToken, twitterAccount.AccessTokenSecret, twitterAccount.Name, await _publicationService.GetCategoryTags(categoryId))); } foreach (var slack in slackApplications) { services.Add(_factory.CreateSlackService(slack.WebHookUrl)); } return(services.ToImmutableList()); }
public async Task Send(int categoryId, string comment, string link) { var pages = await _repository.GetFacebookPages(categoryId); try { foreach (var page in pages) { var facebook = new FacebookClient(page.Token); await facebook.PostOnWall(comment, link); _logger.Write(LogLevel.Info, $"Message was sent to Facebook page `{page.Name}`: `{comment}` `{link}` Category: `{categoryId}`"); } } catch (Exception ex) { _logger.Write(LogLevel.Error, $"Error during send message to Facebook: `{comment}` `{link}` Category: `{categoryId}`", ex); } }