Skip to content

Commit

Permalink
Added error handling on formatting messages (#306)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] authored Nov 19, 2023
1 parent b790aa5 commit 9f981c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/TagzApp.Providers.YouTubeChat/YouTubeChatProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,29 @@ public async Task<IEnumerable<Content>> GetContentForHashtag(Hashtag tag, DateTi
_Status = SocialMediaStatus.Healthy;
_StatusMessage = $"OK -- adding ({contents.Items.Count}) messages for chatid '{LiveChatId}' at {DateTimeOffset.UtcNow}";

try {
try
{
var outItems = contents.Items.Select(i => new Content
{
Author = new Creator
{
Author = new Creator
{
DisplayName = i.AuthorDetails.DisplayName,
ProfileImageUri = new Uri(i.AuthorDetails.ProfileImageUrl),
ProfileUri = new Uri($"https://www.youtube.com/channel/{i.AuthorDetails.ChannelId}")
},
Provider = Id,
ProviderId = i.Id,
Text = i.Snippet.DisplayMessage,
SourceUri = new Uri($"https://youtube.com/livechat/{LiveChatId}"),
Timestamp = DateTimeOffset.Parse(i.Snippet.PublishedAtRaw),
Type = ContentType.Message,
HashtagSought = tag?.Text ?? ""
}).ToArray();
DisplayName = i.AuthorDetails.DisplayName,
ProfileImageUri = new Uri(i.AuthorDetails.ProfileImageUrl),
ProfileUri = new Uri($"https://www.youtube.com/channel/{i.AuthorDetails.ChannelId}")
},
Provider = Id,
ProviderId = i.Id,
Text = i.Snippet.DisplayMessage,
SourceUri = new Uri($"https://youtube.com/livechat/{LiveChatId}"),
Timestamp = DateTimeOffset.Parse(i.Snippet.PublishedAtRaw),
Type = ContentType.Message,
HashtagSought = tag?.Text ?? ""
}).ToArray();
return outItems;

} catch (Exception ex) {
}
catch (Exception ex)
{

Console.WriteLine($"Exception while parsing YouTubeChat: {ex.Message}");

Expand Down
8 changes: 8 additions & 0 deletions src/TagzApp.Storage.Postgres/AzureSafetyModeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public void NotifyNewContent(string hashtag, Content content)

var client = new ContentSafetyClient(new Uri(_ContentSafetyEndpoint), new AzureKeyCredential(_ContentSafetyKey));
var clearText = HtmlCleaner.UnHtml(content.Text);

// Return now if there is no text to analyze
if (string.IsNullOrEmpty(clearText))
{
_NotifyNewMessages.NotifyNewContent(hashtag, content);
return;
}

var request = new AnalyzeTextOptions(clearText);

Response<AnalyzeTextResult> response;
Expand Down
2 changes: 1 addition & 1 deletion src/TagzApp.Web/Areas/Admin/Pages/Users.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<th>User Email</th>
<th>Action</th>
</tr>
@foreach (var user in Model.Users)
@foreach (var user in Model.Users.OrderBy(u => u.DisplayName).ToArray())
{
<tr>
<td>
Expand Down

0 comments on commit 9f981c5

Please sign in to comment.