From 7d934172607b9bf2b12e2304cca6aaaf9fabe1db Mon Sep 17 00:00:00 2001 From: bjoern Date: Mon, 21 May 2018 19:31:06 +0200 Subject: [PATCH] First commit --- Emby.Plugin.TelegramNotification.sln | 25 +++ .../Api/ServerApiEntryPoints.cs | 65 +++++++ .../Configuration/PluginConfiguration.cs | 46 +++++ .../Configuration/config.html | 174 ++++++++++++++++++ .../Emby.Plugin.TelegramNotification.csproj | 15 ++ .../Images/TelegramLogo.png | Bin 0 -> 9333 bytes Emby.Plugin.TelegramNotification/Notifier.cs | 70 +++++++ Emby.Plugin.TelegramNotification/Plugin.cs | 67 +++++++ Emby.Plugin.TelegramNotification/ReadMe.md | 14 ++ 9 files changed, 476 insertions(+) create mode 100644 Emby.Plugin.TelegramNotification.sln create mode 100644 Emby.Plugin.TelegramNotification/Api/ServerApiEntryPoints.cs create mode 100644 Emby.Plugin.TelegramNotification/Configuration/PluginConfiguration.cs create mode 100644 Emby.Plugin.TelegramNotification/Configuration/config.html create mode 100644 Emby.Plugin.TelegramNotification/Emby.Plugin.TelegramNotification.csproj create mode 100644 Emby.Plugin.TelegramNotification/Images/TelegramLogo.png create mode 100644 Emby.Plugin.TelegramNotification/Notifier.cs create mode 100644 Emby.Plugin.TelegramNotification/Plugin.cs create mode 100644 Emby.Plugin.TelegramNotification/ReadMe.md diff --git a/Emby.Plugin.TelegramNotification.sln b/Emby.Plugin.TelegramNotification.sln new file mode 100644 index 0000000..02e22fe --- /dev/null +++ b/Emby.Plugin.TelegramNotification.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Plugin.TelegramNotification", "Emby.Plugin.TelegramNotification\Emby.Plugin.TelegramNotification.csproj", "{0A206AE4-C2EE-4D5A-930F-03BD9B48AE28}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0A206AE4-C2EE-4D5A-930F-03BD9B48AE28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A206AE4-C2EE-4D5A-930F-03BD9B48AE28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A206AE4-C2EE-4D5A-930F-03BD9B48AE28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A206AE4-C2EE-4D5A-930F-03BD9B48AE28}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FF29D56C-B55D-49AB-B561-2E3E356CFC0D} + EndGlobalSection +EndGlobal diff --git a/Emby.Plugin.TelegramNotification/Api/ServerApiEntryPoints.cs b/Emby.Plugin.TelegramNotification/Api/ServerApiEntryPoints.cs new file mode 100644 index 0000000..55dd20f --- /dev/null +++ b/Emby.Plugin.TelegramNotification/Api/ServerApiEntryPoints.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Services; +using Emby.Plugin.TelegramNotification.Configuration; + +namespace Emby.Plugin.TelegramNotification.Api +{ + [Route("/Notification/Telegram/Test/{UserID}", "POST", Summary = "Tests Telegram")] + public class TestNotification : IReturnVoid + { + [ApiMember(Name = "UserID", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string UserID { get; set; } + } + + class ServerApiEndpoints : IService + { + private readonly IHttpClient _httpClient; + private readonly ILogger _logger; + + public ServerApiEndpoints(ILogManager logManager, IHttpClient httpClient) + { + _logger = logManager.GetLogger(GetType().Name); + _httpClient = httpClient; + } + private TeleGramOptions GetOptions(String userID) + { + return Plugin.Instance.Configuration.Options + .FirstOrDefault(i => string.Equals(i.MediaBrowserUserId, userID, StringComparison.OrdinalIgnoreCase)); + } + + public void Post(TestNotification request) + { + var task = PostAsync(request); + Task.WaitAll(task); + } + + public async Task PostAsync(TestNotification request) + { + var options = GetOptions(request.UserID); + string message = "This is a Test"; + + _logger.Debug("Telegram to {0} - {1}", options.BotToken, options.ChatID); + + var httpRequestOptions = new HttpRequestOptions + { + Url = "https://api.telegram.org/bot" + options.BotToken + "/sendmessage?chat_id=" + options.ChatID + "&text=" + message, + CancellationToken = CancellationToken.None + }; + + + using (await _httpClient.Post(httpRequestOptions).ConfigureAwait(false)) + { + + } + + + } + } +} diff --git a/Emby.Plugin.TelegramNotification/Configuration/PluginConfiguration.cs b/Emby.Plugin.TelegramNotification/Configuration/PluginConfiguration.cs new file mode 100644 index 0000000..a1d6018 --- /dev/null +++ b/Emby.Plugin.TelegramNotification/Configuration/PluginConfiguration.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using MediaBrowser.Model.Plugins; + +namespace Emby.Plugin.TelegramNotification.Configuration +{ + /// + /// Class PluginConfiguration + /// + public class PluginConfiguration : BasePluginConfiguration + { + public TeleGramOptions[] Options { get; set; } + + public PluginConfiguration() + { + Options = new TeleGramOptions[] { }; + } + } + + public class TeleGramOptions + { + public Boolean Enabled { get; set; } + public String ChatID { get; set; } + public String BotToken { get; set; } + public String DeviceName { get; set; } + public List SoundList { get; set; } + public int Priority { get; set; } + public string MediaBrowserUserId { get; set; } + + public TeleGramOptions() + { + SoundList = new List + { + new Sound() {Name = "Telegram", Value = "telegram"}, + new Sound() {Name = "Bike", Value = "bike"}, + new Sound() {Name = "Bugle", Value = "bugle"} + }; + } + } + + public class Sound + { + public String Name { get; set; } + public String Value { get; set; } + } +} diff --git a/Emby.Plugin.TelegramNotification/Configuration/config.html b/Emby.Plugin.TelegramNotification/Configuration/config.html new file mode 100644 index 0000000..7284336 --- /dev/null +++ b/Emby.Plugin.TelegramNotification/Configuration/config.html @@ -0,0 +1,174 @@ + + + + Telegram Notifications + + +
+ +
+
+
+

To use Telegram create a bot at @BotFather

+ +
+ +
+ +
+ +
+ +
+ Bot token for your bot, get it from @BotFather +
+
+
+ +
+ Telegram chat ID, get it from @get_id_bot +
+
+
+ +
+
+
+ +
+ +
+
+
+ + +
+ + \ No newline at end of file diff --git a/Emby.Plugin.TelegramNotification/Emby.Plugin.TelegramNotification.csproj b/Emby.Plugin.TelegramNotification/Emby.Plugin.TelegramNotification.csproj new file mode 100644 index 0000000..44eb5e0 --- /dev/null +++ b/Emby.Plugin.TelegramNotification/Emby.Plugin.TelegramNotification.csproj @@ -0,0 +1,15 @@ + + + netstandard1.3; 1.0.0.0 1.0.0.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/Emby.Plugin.TelegramNotification/Images/TelegramLogo.png b/Emby.Plugin.TelegramNotification/Images/TelegramLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..6a444f7d35204111ff9050bf53b9a645fdc9744a GIT binary patch literal 9333 zcmbVy^;;Co7w^&`xl6N3v!sA5-ALooA_CG4FCq=nC5`NoORbb39V#fbbV+x|(jwh; z`Ths@-g)ME=9!su=7-OmGp8m-M@yBIn1L7o0FbJyDd_tU$?G<1O06ziXs1!Jx_SQ!S1ky?(@8cM9JnZ!E1gM+Xy5 zI%z$v3gvO>IULmWC|+xh3C8-lla(8a{Wrw^M-~+K4pj1Qu4ceKnF`+~^$ZU0H%}Bf zhtM6}Ws1Y%US08qZW?-IB_<>X@#fYQk8V}jNH{6fnb3>OLv-&&UG20~(SSE9J(>JR zx1Hu~i*x8+!-U2bbPuzvgmK;LjuKa8q0eKbU%z*MVv!Xdup5}sgHLdp4S3#;`ipuj zW@Y`(Vw}$TGsU+2!Fb8WM5bVVf+g4$+RM(VQU@6JRQZ$nQFvuxF_abDKml&}VE;#V zeqoF`^Ruo)&fy7mB(KT~f)4K~)6bCAmsqHQae&R+pJ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+Wa_?iA*lx0IU5!vN5k*sbqMymSD-5r#=rQi`6&t*Ty~ zi(VO+h}0DC{}_jB(v4x%`kdOy+0~s{{~_2VO$|Yl|9y-?lY6Kk*tQCwMAsV>W0>AY zl68Ag+prPo^po!uL9cpwYkH;2BDUAb#!ct&MN>W)#9-hpps*%g7h~3grGwbqmA364_YR3Xg z|0LVdW6oQiSbFdeA$_0F7D1sZk?Sny8uKDovPrv$h;{U|yGV?m0oWWP}jj(566}aI&t6r2&;*DS`xk^C?k)eda_>u#xM` jgkk^BJ(_I=g9$G0y4bX>t3G}FDg;nh)>5iev string.Equals(i.MediaBrowserUserId, user.Id.ToString("N"), StringComparison.OrdinalIgnoreCase)); + } + + public string Name + { + get { return Plugin.Instance.Name; } + } + + public async Task SendNotification(UserNotification request, CancellationToken cancellationToken) + { + + var options = GetOptions(request.User); + + string message = request.Name; + + _logger.Debug("TeleGram to Token : {0} - {1} - {2}", options.BotToken, options.ChatID, request.Name); + + var _httpRequest = new HttpRequestOptions + { + Url = "https://api.telegram.org/bot" + options.BotToken + "/sendmessage?chat_id=" + options.ChatID + "&text=" + message, + CancellationToken = cancellationToken + }; + + using (await _httpClient.Post(_httpRequest).ConfigureAwait(false)) + { + + } + } + + private bool IsValid(TeleGramOptions options) + { + return !string.IsNullOrEmpty(options.ChatID) && + !string.IsNullOrEmpty(options.BotToken); + } + } +} diff --git a/Emby.Plugin.TelegramNotification/Plugin.cs b/Emby.Plugin.TelegramNotification/Plugin.cs new file mode 100644 index 0000000..2e521e3 --- /dev/null +++ b/Emby.Plugin.TelegramNotification/Plugin.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Plugins; +using MediaBrowser.Model.Plugins; +using MediaBrowser.Model.Serialization; +using Emby.Plugin.TelegramNotification.Configuration; + +namespace Emby.Plugin.TelegramNotification +{ + /// + /// Class Plugin + /// + public class Plugin : BasePlugin, IHasWebPages + { + public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + : base(applicationPaths, xmlSerializer) + { + Instance = this; + } + + private Guid _id = new Guid("890ACB04-34A2-4CDB-8D89-4EA2FE90B0D7"); + public override Guid Id + { + get { return _id; } + } + + public IEnumerable GetPages() + { + return new[] + { + new PluginPageInfo + { + Name = Name, + EmbeddedResourcePath = GetType().Namespace + ".Configuration.config.html" + } + }; + } + + /// + /// Gets the name of the plugin + /// + /// The name. + public override string Name + { + get { return "Telegram Notifications"; } + } + + /// + /// Gets the description. + /// + /// The description. + public override string Description + { + get + { + return "Sends notifications via Telegram Service."; + } + } + + /// + /// Gets the instance. + /// + /// The instance. + public static Plugin Instance { get; private set; } + } +} diff --git a/Emby.Plugin.TelegramNotification/ReadMe.md b/Emby.Plugin.TelegramNotification/ReadMe.md new file mode 100644 index 0000000..ea9bdfc --- /dev/null +++ b/Emby.Plugin.TelegramNotification/ReadMe.md @@ -0,0 +1,14 @@ +# Emby.Plugin.TelegramNotification + +Emby Server Plugin for sending notifications to a Telegram bot. + +## Install +1. Install the Plugin by downloading the DLL (or build it yourself using VS2017) and putting it into your Emby Plugin folder +2. Restart your Emby Server +3. Talk to Bodfather to create your Telegram ot +4. Start a chat with your bot and use @get_id_bot to get the Chat ID +5. Use the Settings Page of the Plugin to set Bot Token and Chat ID +6. Activate the Telegram Notifications Plugin in the desired Server notifications + +Based on the raw Telegram Plugin of an unknown Author, spiced up with pieces of the Slack Notification Author and much googleling. +Please test it as much as you can. \ No newline at end of file