Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error handling on formatting messages #306

Merged
merged 5 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading