mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
parent
018cd7a072
commit
d5477adc6b
24 changed files with 613 additions and 8 deletions
10
src/Ombi.Api.Slack/ISlackApi.cs
Normal file
10
src/Ombi.Api.Slack/ISlackApi.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Threading.Tasks;
|
||||
using Ombi.Api.Slack.Models;
|
||||
|
||||
namespace Ombi.Api.Slack
|
||||
{
|
||||
public interface ISlackApi
|
||||
{
|
||||
Task<string> PushAsync(string team, string token, string service, SlackNotificationBody message);
|
||||
}
|
||||
}
|
30
src/Ombi.Api.Slack/Models/SlackNotificationBody.cs
Normal file
30
src/Ombi.Api.Slack/Models/SlackNotificationBody.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Ombi.Api.Slack.Models
|
||||
{
|
||||
public class SlackNotificationBody
|
||||
{
|
||||
[JsonConstructor]
|
||||
public SlackNotificationBody()
|
||||
{
|
||||
username = "Ombi";
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
private string _username;
|
||||
public string username
|
||||
{
|
||||
get => _username;
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
_username = value;
|
||||
}
|
||||
}
|
||||
public string channel { get; set; }
|
||||
public string text { get; set; }
|
||||
|
||||
public string icon_url { get; set; }
|
||||
public string icon_emoji { get; set; }
|
||||
}
|
||||
}
|
11
src/Ombi.Api.Slack/Ombi.Api.Slack.csproj
Normal file
11
src/Ombi.Api.Slack/Ombi.Api.Slack.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
42
src/Ombi.Api.Slack/SlackApi.cs
Normal file
42
src/Ombi.Api.Slack/SlackApi.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Api.Slack.Models;
|
||||
|
||||
namespace Ombi.Api.Slack
|
||||
{
|
||||
public class SlackApi : ISlackApi
|
||||
{
|
||||
public SlackApi(IApi api)
|
||||
{
|
||||
Api = api;
|
||||
}
|
||||
|
||||
private IApi Api { get; }
|
||||
private const string BaseUrl = "https://hooks.slack.com/";
|
||||
public async Task<string> PushAsync(string team, string token, string service, SlackNotificationBody message)
|
||||
{
|
||||
|
||||
var request = new Request($"/services/{team}/{service}/{token}", BaseUrl, HttpMethod.Post);
|
||||
dynamic body = new ExpandoObject();
|
||||
body.channel = message.channel;
|
||||
body.text = message.text;
|
||||
body.username = message.username;
|
||||
|
||||
if (!string.IsNullOrEmpty(message.icon_url))
|
||||
{
|
||||
body.icon_url = message.icon_url;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(message.icon_emoji))
|
||||
{
|
||||
body.icon_emoji = message.icon_emoji;
|
||||
}
|
||||
request.AddJsonBody(body);
|
||||
request.ApplicationJsonContentType();
|
||||
|
||||
return await Api.Request<string>(request);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue