From cfd3a0a58dbacbdf1983b0b25323b8eb6ef88cd1 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Mon, 16 Jan 2023 19:34:26 +0000 Subject: [PATCH] 50_SSChatBot: new attr spareHost, sparePort git-svn-id: https://svn.fhem.de/fhem/trunk@27073 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/50_SSChatBot.pm | 172 ++++++++++++++++++++++++++------------ 2 files changed, 121 insertions(+), 52 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 75218073f..5c1616c7b 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 50_SSChatBot: new attr spareHost, sparePort - feature: 6.2 released - 2023-01-14 (6.2) diff --git a/fhem/FHEM/50_SSChatBot.pm b/fhem/FHEM/50_SSChatBot.pm index 829427a11..d77343611 100644 --- a/fhem/FHEM/50_SSChatBot.pm +++ b/fhem/FHEM/50_SSChatBot.pm @@ -3,7 +3,7 @@ ######################################################################################################################### # 50_SSChatBot.pm # -# (c) 2019-2020 by Heiko Maaz +# (c) 2019-2023 by Heiko Maaz # e-mail: Heiko dot Maaz at t-online dot de # # This Module can be used to operate as Bot for Synology Chat. @@ -135,6 +135,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "1.13.0" => "14.01.2023 new attr spareHost, sparePort ", "1.12.1" => "28.11.2020 fix cannot send after received anything, fix greedy regex in _botCGIcheckData ", "1.12.0" => "23.11.2020 generate event CHAT_INITIALIZED when users are once loaded, Forum: https://forum.fhem.de/index.php/topic,105714.msg1103700.html#msg1103700 ". "postpone new operation is one ist still running ", @@ -245,6 +246,8 @@ sub Initialize { "allowedUserForOwn:--wait#for#userlist-- ". "ownCommand1 ". "showTokenInLog:1,0 ". + "spareHost: ". + "sparePort: ". "httptimeout ". $readingFnAttributes; @@ -365,6 +368,8 @@ sub Delete { return; } +################################################################ +# Attr Management ################################################################ sub Attr { my ($cmd,$name,$aName,$aVal) = @_; @@ -395,6 +400,10 @@ sub Attr { readingsEndUpdate ($hash, 1); } + if (($aName =~ m/spare/x)) { + InternalTimer(gettimeofday()+1.5, "FHEM::SSChatBot::initOnBoot", $hash, 0) if($init_done); + } + if ($cmd eq "set") { if ($aName =~ m/httptimeout/x) { unless ($aVal =~ /^\d+$/x) { return "The Value for $aName is not valid. Use only figures 1-9 !";} @@ -403,8 +412,8 @@ sub Attr { if ($aName =~ m/ownCommand([1-9][0-9]*)$/x) { my $num = $1; return qq{The value of $aName must start with a slash like "/Weather ".} unless ($aVal =~ /^\//x); - addToDevAttrList($name, "ownCommand".($num+1)); # add neue ownCommand dynamisch - } + addToDevAttrList($name, "ownCommand".($num+1)); # add neue ownCommand dynamisch + } } return; @@ -526,17 +535,18 @@ sub _setasyncSendItem { $text = join(" ", @t) if(!$text); } - if($svg) { # Versenden eines Plotfiles + if($svg) { # Versenden eines Plotfiles my ($err, $file) = plotPngToFile ($name, $svg); return if($err); - my $FW = $hash->{FW}; - my $csrf = $defs{$FW}{CSRFTOKEN} // ""; - $fileUrl = (split("sschat", $hash->{OUTDEF}))[0]; - $fileUrl .= "sschat/www/images/$file?&fwcsrf=$csrf"; + my $FW = $hash->{FW}; + my $csrf = $defs{$FW}{CSRFTOKEN} // ""; + my $FWname = AttrVal ($FW, 'webname', 'sschat'); + $fileUrl = (split "$FWname", $hash->{OUTDEF})[0]; + $fileUrl .= "$FWname/www/images/$file?&fwcsrf=$csrf"; - $fileUrl = formString($fileUrl, "text"); - $text = $svg if(!$text); # Name des SVG-Plots + Optionen als Standardtext + $fileUrl = formString($fileUrl, "text"); + $text = $svg if(!$text); # Name des SVG-Plots + Optionen als Standardtext } return qq{Your sendstring is incorrect. It must contain at least text with the "text=" tag like text="..."\nor only some text like "this is a test" without the "text=" tag.} if(!$text); @@ -770,6 +780,7 @@ return $ret; sub initOnBoot { my $hash = shift; my $name = $hash->{NAME}; + my ($ret,$csrf,$fuuid); RemoveInternalTimer($hash, "FHEM::SSChatBot::initOnBoot"); @@ -793,12 +804,12 @@ sub initOnBoot { } if (!defined($defs{$FW})) { # wenn Device "WEBSSChat" wirklich nicht existiert - Log3($name, 3, "$name - Creating new FHEMWEB instance \"$FW\" with webname \"$FWname\"... "); + Log3 ($name, 3, "$name - Creating new FHEMWEB instance \"$FW\" with webname \"$FWname\"... "); $ret = CommandDefine(undef, "$FW FHEMWEB $port global"); } if(!$ret) { - Log3($name, 3, "$name - FHEMWEB instance \"$FW\" with webname \"$FWname\" created"); + Log3 ($name, 3, "$name - FHEMWEB instance \"$FW\" with webname \"$FWname\" created"); $hash->{FW} = $FW; $fuuid = $defs{$FW}{FUUID}; @@ -812,7 +823,7 @@ sub initOnBoot { CommandAttr(undef, "$FW stylesheetPrefix default"); } else { - Log3($name, 2, "$name - ERROR while creating FHEMWEB instance ".$hash->{FW}." with webname \"$FWname\" !"); + Log3 ($name, 2, "$name - ERROR while creating FHEMWEB instance ".$hash->{FW}." with webname \"$FWname\" !"); readingsBeginUpdate($hash); readingsBulkUpdate ($hash, "state", "ERROR in initialization - see logfile"); readingsEndUpdate ($hash,1); @@ -820,21 +831,24 @@ sub initOnBoot { } if(!$ret) { - CommandGet(undef, "$name chatUserlist"); # Chatuser Liste initial abrufen + CommandGet(undef, "$name chatUserlist"); # Chatuser Liste initial abrufen - my $host = hostname(); # eigener Host - my $fqdn = hostfqdn(); # MYFQDN eigener Host - chop($fqdn) if($fqdn =~ /\.$/x); # eventuellen "." nach dem FQDN entfernen + my $host = hostname(); # eigener Host + my $fqdn = hostfqdn(); # MYFQDN eigener Host + chop($fqdn) if($fqdn =~ /\.$/x); # eventuellen "." nach dem FQDN entfernen my $FWchatport = $defs{$FW}{PORT}; - my $FWprot = AttrVal($FW, "HTTPS", 0); - $FWname = AttrVal($FW, "webname", 0); + my $FWprot = AttrVal ($FW, 'HTTPS', 0); + $FWname = AttrVal ($FW, 'webname', $FWname); CommandAttr(undef, "$FW csrfToken none") if(!AttrVal($FW, "csrfToken", "")); $csrf = $defs{$FW}{CSRFTOKEN} // ""; - $hash->{OUTDEF} = ($FWprot ? "https" : "http")."://".($fqdn // $host).":".$FWchatport."/".$FWname."/outchat?botname=".$name."&fwcsrf=".$csrf; + my $sparehost = AttrVal ($name, 'spareHost', ($fqdn // $host)); # Forum: https://forum.fhem.de/index.php/topic,105714.msg1256613.html#msg1256613 + my $spareport = AttrVal ($name, 'sparePort', $FWchatport); # Forum: https://forum.fhem.de/index.php/topic,105714.msg1256613.html#msg1256613 + + $hash->{OUTDEF} = ($FWprot ? "https" : "http")."://".$sparehost.":".$spareport."/".$FWname."/outchat?botname=".$name."&fwcsrf=".$csrf; - addExtension($name, "FHEM::SSChatBot::botCGI", "outchat"); + addExtension ($name, 'FHEM::SSChatBot::botCGI', 'outchat'); $hash->{HELPER}{INFIX} = "outchat"; } } @@ -1340,7 +1354,7 @@ sub addExtension { $data{FWEXT}{$url}{FUNC} = $func; $data{FWEXT}{$url}{LINK} = $link; - Log3($name, 3, "$name - SSChatBot \"$name\" for URL $url registered"); + Log3 ($name, 3, "$name - SSChatBot \"$name\" for URL $url (new) registered"); return; } @@ -2044,9 +2058,9 @@ return ($cr, $state);

- Allgemeine Information zum Nachrichtempfang
- Um Befehle vom Chat Server an FHEM zu senden, werden Slash-Befehle (/) verwendet. Sie sind vor der Verwendung im Synology - Chat und ggf. zusätzlich im SSChatBot Device (User spezifische Befehle) zu konfigurieren.

+ General information on message reception
+ To send commands from Chat Server to FHEM, slash commands (/) are used. They have to be configured before using them in Synology + Chat and if necessary additionally in SSChatBot Device (User specific commands).

The following command forms are supported:

+ + + + @@ -2303,7 +2343,7 @@ return ($cr, $state); =end html =begin html_DE - +

SSChatBot