diff --git a/fhem/CHANGED b/fhem/CHANGED index f0d6a7094..fe4ff25c2 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. + - change: 50_TelegramBot: new reading msgDate and corrections - feature: 72_FRITZBOX: Attr. enableWanInfo -> enableWLANneighbors Attr. wlanNeighborsPrefix Fehlerkorrekturen diff --git a/fhem/FHEM/50_TelegramBot.pm b/fhem/FHEM/50_TelegramBot.pm index e53aebcfe..9b8c11ed0 100644 --- a/fhem/FHEM/50_TelegramBot.pm +++ b/fhem/FHEM/50_TelegramBot.pm @@ -194,7 +194,11 @@ # #msg1168649: Corrected logging verbose to make 0_None work # caption parseMode / formatting also available for photo and video sends -# +# avoid warning for incomplete msgDelete commands +# replaceSetMagic on favorites not done before execution +# add reading msgDate +# update documentation + # ############################################################################## # TASKS @@ -202,7 +206,6 @@ # Customize Favoriten beendet --> msg1133794 # Option to delete message at the end insteda of sending "-" # -# # change doc to have "a name" on attributes to allow inline help # Restructure help in logical blocks # @@ -766,17 +769,19 @@ sub TelegramBot_Set($@) return "TelegramBot_Set: Command $cmd, msgId must be given as first parameter before peer" if ( $msgid =~ /^@/ ); $numberOfArgs--; - while ( $args[0] =~ /^@(..+)$/ ) { - my $ppart = $1; - return "TelegramBot_Set: Command $cmd, need exactly one peer" if ( defined( $peers ) ); - $peers .= " " if ( defined( $peers ) ); - $peers = "" if ( ! defined( $peers ) ); - $peers .= $ppart; - - shift @args; - last if ( int(@args) == 0 ); + if ( int(@args) > 0 ) { + while ( $args[0] =~ /^@(..+)$/ ) { + my $ppart = $1; + return "TelegramBot_Set: Command $cmd, need exactly one peer" if ( defined( $peers ) ); + $peers .= " " if ( defined( $peers ) ); + $peers = "" if ( ! defined( $peers ) ); + $peers .= $ppart; + + shift @args; + last if ( int(@args) == 0 ); + } } - + if ( ! defined( $peers ) ) { $peers = AttrVal($name,'defaultPeer',undef); return "TelegramBot_Set: Command $cmd, without explicit peer requires defaultPeer being set" if ( ! defined($peers) ); @@ -1469,14 +1474,14 @@ sub TelegramBot_ExecuteCommand($$$$;$$) { if ( ! defined( $ret ) ) { # run replace set magic on command - first my %dummy; - my ($err, @a) = ReplaceSetMagic(\%dummy, 0, ( $cmd ) ); + # my ($err, @a) = ReplaceSetMagic(\%dummy, 0, ( $cmd ) ); - if ( $err ) { - Log3 $name, 1, "TelegramBot_ExecuteCommand $name: parse cmd failed on ReplaceSetmagic with :$err: on :$cmd:"; - } else { - $cmd = join(" ", @a); - Log3 $name, 4, "TelegramBot_ExecuteCommand $name: parse cmd returned :$cmd:"; - } + # if ( $err ) { + # Log3 $name, 1, "TelegramBot_ExecuteCommand $name: parse cmd failed on ReplaceSetmagic with :$err: on :$cmd:"; + # } else { + # $cmd = join(" ", @a); + # Log3 $name, 4, "TelegramBot_ExecuteCommand $name: parse cmd returned :$cmd:"; + # } $ret = AnalyzeCommandChain( $hash, $cmd ); @@ -2506,6 +2511,8 @@ sub TelegramBot_ParseMsg($$$) my $mid = $message->{message_id}; + my $mdate = FmtDateTime( $message->{date} ); + my $from = $message->{from}; if ( ! defined( $from ) ) { Log3 $name, 3, "TelegramBot $name: No from user in message - blocked"; @@ -2667,6 +2674,7 @@ sub TelegramBot_ParseMsg($$$) readingsBeginUpdate($hash); readingsBulkUpdate($hash, "prevMsgId", $hash->{READINGS}{msgId}{VAL}); + readingsBulkUpdate($hash, "prevMsgDate", $hash->{READINGS}{msgDate}{VAL}); readingsBulkUpdate($hash, "prevMsgPeer", $hash->{READINGS}{msgPeer}{VAL}); readingsBulkUpdate($hash, "prevMsgPeerId", $hash->{READINGS}{msgPeerId}{VAL}); readingsBulkUpdate($hash, "prevMsgChat", $hash->{READINGS}{msgChat}{VAL}); @@ -2679,6 +2687,7 @@ sub TelegramBot_ParseMsg($$$) readingsBeginUpdate($hash); readingsBulkUpdate($hash, "msgId", $mid); + readingsBulkUpdate($hash, "msgDate", $mdate); readingsBulkUpdate($hash, "msgPeer", TelegramBot_GetFullnameForContact( $hash, $mpeernorm )); readingsBulkUpdate($hash, "msgPeerId", $mpeernorm); readingsBulkUpdate($hash, "msgChat", TelegramBot_GetFullnameForContact( $hash, ((!$chatId)?$mpeernorm:$chatId) ) ); @@ -4137,6 +4146,7 @@ sub TelegramBot_BinaryFileWrite($$$) {
  • msgId <text>
    The id of the last received message is stored in this reading. For secret chats a value of -1 will be given, since the msgIds of secret messages are not part of the consecutive numbering
  • +
  • msgDate <timestamp>
    The timestamp of the last message receied representing the time when it was sent to telegram
  • msgPeer <text>
    The sender name of the last received message (either full name or if not available @username)
  • msgPeerId <text>
    The sender id of the last received message
  • msgChat <text>
    The name of the Chat in which the last message was received (might be the peer if no group involved)
  • @@ -4147,6 +4157,7 @@ sub TelegramBot_BinaryFileWrite($$$) {
  • prevMsgId <text>
    The id of the SECOND last received message is stored in this reading
  • +
  • prevMsgDate <timestamp>
    The timestamp of the SECOND last received message . g
  • prevMsgPeer <text>
    The sender name of the SECOND last received message (either full name or if not available @username)
  • prevMsgPeerId <text>
    The sender id of the SECOND last received message
  • prevMsgText <text>
    The SECOND last received message text is stored in this reading