first commit

This commit is contained in:
2026-08-02 23:33:31 +02:00
commit fd62224511
41 changed files with 2348 additions and 0 deletions
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>BlubbFish.IoT.Pocsag.BosServerTelegram</RootNamespace>
<Version>1.1.0</Version>
<Description>
1.1.0 make it running on linux
1.0.0 Init
</Description>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj" />
<ProjectReference Include="..\..\Utils\ConnectorDataMqtt\ConnectorDataMqtt\ConnectorDataMqtt.csproj" />
<ProjectReference Include="..\..\Utils\ConnectorUserTelegram\ConnectorUserTelegram\ConnectorUserTelegram.csproj" />
<ProjectReference Include="..\..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj" />
<ProjectReference Include="..\..\Utils\Utils\Utils\Utils.csproj" />
<ProjectReference Include="..\BosServerDatatypes\BosServerDatatypes.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="config-example\settings.conf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
+126
View File
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
namespace BlubbFish.IoT.Pocsag.BosServerTelegram {
class Program : ABot {
private readonly ABackend bmqtt;
private readonly ABackend btelegram;
private readonly Dictionary<String, String> bosconf;
static void Main(String[] args) => new Program(args, false, "bstelegram");
public Program(String[] args, Boolean fileLogging, String configSearchPath) : base(args, fileLogging, configSearchPath) {
this.bmqtt = ABackend.GetInstance(InIReader.GetInstance("settings").GetSection("backend"));
this.bmqtt.MessageIncomming += this.Mqtt_MessageIncomming;
this.bmqtt.MessageSending += this.Mqtt_MessageSending;
this.btelegram = ABackend.GetInstance(InIReader.GetInstance("settings").GetSection("usernotification"));
this.btelegram.MessageIncomming += this.Telegram_MessageIncomming;
this.btelegram.MessageSending += this.Telegram_MessageSending;
this.bosconf = InIReader.GetInstance("settings").GetSection("bosservertelegram");
this.SendMqtt(new Message("Anwendung BosServerTelegram Version " + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion + " gestartet."));
this.WaitForShutdown();
this.SendMqtt(new Message("Anwendung BosServerTelegram wurde beendet... Ob das so soll?"));
System.Threading.Thread.Sleep(5000);
this.Dispose();
}
private void Telegram_MessageSending(Object sender, BackendEvent telegram) {
try {
Console.WriteLine("=> Telegram [" + telegram.From.ToString() + "]: " + telegram.Message);
} catch(Exception e) {
Helper.WriteError("Backend_MessageSending(): " + e.Message + "\n\n" + e.StackTrace);
}
}
private void Mqtt_MessageSending(Object sender, BackendEvent mqtt) {
try {
Console.WriteLine("=> MQTT [" + mqtt.From.ToString() + "]: " + mqtt.Message);
} catch(Exception e) {
Helper.WriteError("Backend_MessageSending(): " + e.Message + "\n\n" + e.StackTrace);
}
}
private void Telegram_MessageIncomming(Object sender, BackendEvent telegram) {
try {
if(telegram.From is Tuple<Int64, String, Int64, String> t) {
Console.WriteLine("<= Telegram-API [" + t.Item1.ToString() + "]: " + telegram.Message);
String task = telegram.Message.ToLower();
if(task == "idea" || task == "leer") {
if(!(t.Item4 is null)) {
Match x = Regex.Match(t.Item4, @"^\[[A-Z]+\] ([0-9]+): .*?$");
if(x.Success) {
if(t.Item1 == Int64.Parse(this.bosconf["special"])) {
this.SendMqtt(new AddFilter(x.Groups[1].ToString(), task, t.Item2));
} else {
this.SendTelegram(new Message("Hallo " + t.Item2 + ", https://xkcd.com/838/"), t.Item3.ToString());
}
} else {
this.SendTelegram(new Message("Hallo " + t.Item2 + ", ich kann die RIC in der zitierten Nachricht nicht finden."), t.Item3.ToString());
}
} else {
this.SendTelegram(new Message("Hallo " + t.Item2 + ", du hast keine Nachricht zitiert."), t.Item3.ToString());
}
}
}
} catch(Exception e) {
Helper.WriteError("Backend_MessageIncomming(): " + e.Message + "\n\n" + e.StackTrace);
}
}
private void Mqtt_MessageIncomming(Object sender, BackendEvent mqtt) {
try {
Console.WriteLine("<= MQTT [" + mqtt.From.ToString() + "]: " + mqtt.Message);
if(AMqttMessage.CheckJson(mqtt.Message, typeof(PocsagParsed))) {
PocsagParsed p = PocsagParsed.ConvertJson(mqtt.Message);
if(p.Isprivate) {
this.SendTelegram(p, this.bosconf["special"]);
}
if(p.Sendonline) {
this.SendTelegram(p, this.bosconf["group"]);
}
} else if(AMqttMessage.CheckJson(mqtt.Message, typeof(Message))) {
this.SendTelegram(Message.ConvertJson(mqtt.Message), this.bosconf["group"]);
}
} catch(Exception e) {
Helper.WriteError("Backend_MessageIncomming(): " + e.Message + "\n\n" + e.StackTrace);
}
}
private void SendMqtt(AMqttMessage msg) {
try {
((Utils.IoT.Connector.Data.Mqtt)this.bmqtt).Send(this.bosconf["topic"] + "/" + msg.Datatype, msg.ToJson());
} catch(Exception e) {
Helper.WriteError("SendMqtt(): " + e.Message + "\n\n" + e.StackTrace);
}
}
private void SendTelegram(AMqttMessage msg, String target) {
((Utils.IoT.Connector.User.Telegram)this.btelegram).Send(msg.ToString(), target);
if(msg is PocsagParsed p && p.Geo is GeoData) {
((Utils.IoT.Connector.User.Telegram)this.btelegram).SendLocationWithText(p.ToTitleString(), p.ToTextString(), p.Geo.Latitude, p.Geo.Longitude, target);
}
}
public override void Dispose() {
if(this.bmqtt != null) {
this.bmqtt.Dispose();
}
if(this.btelegram != null) {
this.btelegram.Dispose();
}
base.Dispose();
}
}
}
@@ -0,0 +1,20 @@
[logging]
path=/var/log/bstelegram.log
debug=true
[backend]
type=Mqtt
backendtype=Data
server=localhost
topic=bosmon/pocsag-parsed;bosmon/message
[usernotification]
type=Telegram
backendtype=User
telegram-key=[api_key]
default-chat=[chatgruppe]
[bosservertelegram]
topic=bosmon
group=[chatgruppe]
special=[chat_person]
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
CSPROJFILE="BosServerTelegram.csproj"
VMAJOR=$(grep -e "<Version>" ../$CSPROJFILE | cut -d'>' -f 2 | cut -d'<' -f 1 | cut -d'.' -f 1)
VMINOR=$(grep -e "<Version>" ../$CSPROJFILE | cut -d'>' -f 2 | cut -d'<' -f 1 | cut -d'.' -f 2)
VBUILD=$(grep -e "<Version>" ../$CSPROJFILE | cut -d'>' -f 2 | cut -d'<' -f 1 | cut -d'.' -f 3)
mkdir -p ../deb
mkdir -p ../Builds
export NAME=bstelegram
export MAINAINER="BlubbFish <dev@blubbfish.net>"
export VERSION="$VMAJOR.$VMINOR-$VBUILD"
export DESCRIPTION="bstelegram sends parsed pocsag messages to to telegram chat"
export DEPENDENCIES="dotnet-runtime-8.0 (>= 8.0.0)"
export LOGFILE="/var/log/bstelegram.log"
export EXEPATH=BosServerTelegram.dll
export RUNNER=/usr/share/dotnet/dotnet
export COPYEXEC="../bin/Release/netcoreapp3.1/*.dll ../bin/Release/netcoreapp3.1/BosServerTelegram.deps.json ../bin/Release/netcoreapp3.1/BosServerTelegram.runtimeconfig.json"
export COPYCONFIG="../bin/Release/netcoreapp3.1/config-example/*.conf"
export CONFIGREPLACEASK=settings.conf
cd ../deb
export PLATFORM=armhf
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/control-build.sh | bash
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/pre-post-build.sh | bash
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/service-build.sh | bash
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/logrotate-build.sh | bash
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/build-deb.sh | bash
export PLATFORM=amd64
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/control-build.sh | bash
curl -s https://git.blubbfish.net/vs_utils/CI-Scripts/raw/branch/master/deb/build-deb.sh | bash
cd ..
rm deb -rf
cp Builds/* ../../Builds/
rm Builds -rf