mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Added Telegram Notification support, Not tested.
This commit is contained in:
parent
5e48c66325
commit
e526c1071a
25 changed files with 494 additions and 25 deletions
9
src/Ombi.Api.Telegram/ITelegramApi.cs
Normal file
9
src/Ombi.Api.Telegram/ITelegramApi.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api.Telegram
|
||||
{
|
||||
public interface ITelegramApi
|
||||
{
|
||||
Task Send(string message, string botApi, string chatId, string parseMode);
|
||||
}
|
||||
}
|
11
src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj
Normal file
11
src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
33
src/Ombi.Api.Telegram/TelegramApi.cs
Normal file
33
src/Ombi.Api.Telegram/TelegramApi.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Api.Telegram
|
||||
{
|
||||
public class TelegramApi : ITelegramApi
|
||||
{
|
||||
public TelegramApi(IApi api)
|
||||
{
|
||||
_api = api;
|
||||
}
|
||||
|
||||
private readonly IApi _api;
|
||||
private const string BaseUrl = "https://api.telegram.org/bot";
|
||||
|
||||
|
||||
public async Task Send(string message, string botApi, string chatId, string parseMode)
|
||||
{
|
||||
var request = new Request($"{botApi}/sendMessage", BaseUrl, HttpMethod.Post);
|
||||
request.AddQueryString("chat_id", chatId);
|
||||
|
||||
var body = new
|
||||
{
|
||||
text = message,
|
||||
parse_mode = parseMode
|
||||
};
|
||||
|
||||
request.AddJsonBody(body);
|
||||
await _api.Request(request);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue