feat: implement song submission support, refs #5
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
|
||||
using song_of_the_day;
|
||||
|
||||
public class LinkPreviewAttachment
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Base64Image { get; set; }
|
||||
}
|
||||
|
||||
public class SignalIntegration
|
||||
{
|
||||
private readonly ILogger<SignalIntegration> logger;
|
||||
@@ -15,7 +23,8 @@ public class SignalIntegration
|
||||
|
||||
var http = new HttpClient()
|
||||
{
|
||||
BaseAddress = new Uri(uri + ":" + port)
|
||||
BaseAddress = new Uri(uri + ":" + port),
|
||||
Timeout = TimeSpan.FromSeconds(180),
|
||||
};
|
||||
apiClient = new swaggerClient(http);
|
||||
apiClient.BaseUrl = "";
|
||||
@@ -26,6 +35,12 @@ public class SignalIntegration
|
||||
|
||||
private string phoneNumber;
|
||||
|
||||
public async Task GetMessagesAsync()
|
||||
{
|
||||
var messages = await apiClient.ReceiveAsync(this.phoneNumber, "120", "true", "true", "50", "false");
|
||||
logger.LogInformation($"Received {messages.Count} Signal messages.");
|
||||
}
|
||||
|
||||
public async Task ListGroupsAsync()
|
||||
{
|
||||
logger.LogDebug("Listing all groups for phone number: {PhoneNumber}", this.phoneNumber);
|
||||
@@ -51,7 +66,7 @@ public class SignalIntegration
|
||||
SendMessageV2 data = new SendMessageV2();
|
||||
data.Recipients = new List<string>();
|
||||
data.Recipients.Add(AppConfiguration.Instance.SignalGroupId);
|
||||
data.Message = message;
|
||||
data.Message = (AppConfiguration.Instance.UseBotTag ? "**[Proggy]**\n" : "") + message;
|
||||
data.Text_mode = SendMessageV2Text_mode.Styled;
|
||||
data.Number = AppConfiguration.Instance.HostPhoneNumber;
|
||||
var response = await apiClient.Send2Async(data);
|
||||
@@ -62,6 +77,29 @@ public class SignalIntegration
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendMessageToGroupAsync(string message, LinkPreviewAttachment previewData)
|
||||
{
|
||||
try
|
||||
{
|
||||
SendMessageV2 data = new SendMessageV2();
|
||||
data.Recipients = new List<string>();
|
||||
data.Recipients.Add(AppConfiguration.Instance.SignalGroupId);
|
||||
data.Message = (AppConfiguration.Instance.UseBotTag ? "**[Proggy]**\n" : "") + message;
|
||||
data.Text_mode = SendMessageV2Text_mode.Styled;
|
||||
data.Number = AppConfiguration.Instance.HostPhoneNumber;
|
||||
data.Link_preview = new LinkPreviewType();
|
||||
data.Link_preview.Url = previewData.Url;
|
||||
data.Link_preview.Title = previewData.Title;
|
||||
data.Link_preview.Description = previewData.Description;
|
||||
data.Link_preview.Base64_thumbnail = previewData.Base64Image;
|
||||
var response = await apiClient.Send2Async(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("Exception (SendMessageToGroupAsync): " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendMessageToUserAsync(string message, string userId)
|
||||
{
|
||||
try
|
||||
@@ -80,6 +118,29 @@ public class SignalIntegration
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendMessageToUserAsync(string message, LinkPreviewAttachment previewData, string userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
SendMessageV2 data = new SendMessageV2();
|
||||
data.Recipients = new List<string>();
|
||||
data.Recipients.Add(userId);
|
||||
data.Message = (AppConfiguration.Instance.UseBotTag ? "**[Proggy]**\n" : "") + message;
|
||||
data.Text_mode = SendMessageV2Text_mode.Styled;
|
||||
data.Number = AppConfiguration.Instance.HostPhoneNumber;
|
||||
data.Link_preview = new LinkPreviewType();
|
||||
data.Link_preview.Url = previewData.Url;
|
||||
data.Link_preview.Title = previewData.Title;
|
||||
data.Link_preview.Description = previewData.Description;
|
||||
data.Link_preview.Base64_thumbnail = previewData.Base64Image;
|
||||
var response = await apiClient.Send2Async(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("Exception (SendMessageToUserAsync): " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task IntroduceUserAsync(User user)
|
||||
{
|
||||
if (user == null || user.SignalMemberId == null)
|
||||
|
Reference in New Issue
Block a user