mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-26 10:34:52 +00:00
50_TelegramBot: parseMode for Photo & Video / FIX: 0_none logmode
git-svn-id: https://svn.fhem.de/fhem/trunk@24867 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
157c3fb3bb
commit
a77f6b3e14
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- change: 50_TelegramBot: parseMode for Photo & Video / FIX: 0_none logmode
|
||||||
- feature: 19_Revolt: add standard attributes ignore, showtime etc.
|
- feature: 19_Revolt: add standard attributes ignore, showtime etc.
|
||||||
- feature: 23_LUXTRONIK2: new set parameter ventBOSUPCircPumpDeaerate
|
- feature: 23_LUXTRONIK2: new set parameter ventBOSUPCircPumpDeaerate
|
||||||
- bugfix: 73_DoorBird: Firmware update parsing fixed
|
- bugfix: 73_DoorBird: Firmware update parsing fixed
|
||||||
|
@ -181,21 +181,29 @@
|
|||||||
# replyKeyboardRemove - #msg592808
|
# replyKeyboardRemove - #msg592808
|
||||||
# replace single semicolons in favorites (with double semicolons) - msg1078989
|
# replace single semicolons in favorites (with double semicolons) - msg1078989
|
||||||
# FIX: answercallback always if querydata is set
|
# FIX: answercallback always if querydata is set
|
||||||
|
|
||||||
# Add new sendformat video to set - cmd sendVideo / silentVideo
|
# Add new sendformat video to set - cmd sendVideo / silentVideo
|
||||||
# Recognize stream of video format (esp. mp4 - needs testing)
|
# Recognize stream of video format (esp. mp4 - needs testing)
|
||||||
# recognize stream isMedia with negative numbers
|
# recognize stream isMedia with negative numbers
|
||||||
# document video commands
|
# document video commands
|
||||||
#SVN 21.10.2020
|
#SVN 21.10.2020
|
||||||
|
|
||||||
|
# Also support edited_message updates
|
||||||
|
# check parseMsg if $from not there --> log then
|
||||||
|
# removed new_chat_participant
|
||||||
|
# log all new contacts - with source
|
||||||
|
# #msg1168649: Corrected logging verbose to make 0_None work
|
||||||
|
# caption parseMode / formatting also available for photo and video sends
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# TASKS
|
# TASKS
|
||||||
#
|
#
|
||||||
|
# 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
|
# change doc to have "a name" on attributes to allow inline help
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Restructure help in logical blocks
|
# Restructure help in logical blocks
|
||||||
#
|
#
|
||||||
# queryDialogStart / queryDialogEnd - keep msg id
|
# queryDialogStart / queryDialogEnd - keep msg id
|
||||||
@ -1817,33 +1825,16 @@ sub TelegramBot_SendIt($$$$$;$$$)
|
|||||||
# DEBUG OPTION
|
# DEBUG OPTION
|
||||||
# $hash->{HU_DO_PARAMS}->{url} = "http://requestb.in/1ibjnj81" if ( $msg =~ /^ZZZ/ );
|
# $hash->{HU_DO_PARAMS}->{url} = "http://requestb.in/1ibjnj81" if ( $msg =~ /^ZZZ/ );
|
||||||
|
|
||||||
my $parseMode = TelegramBot_AttrNum($name,"parseModeSend","0" );
|
my $parseMode = 0;
|
||||||
if ( $parseMode == 1 ) {
|
($parseMode, $msg) = TelegramBot_evalParseMode( $hash, $msg );
|
||||||
$parseMode = "Markdown";
|
|
||||||
} elsif ( $parseMode == 2 ) {
|
|
||||||
$parseMode = "HTML";
|
|
||||||
} elsif ( $parseMode == 3 ) {
|
|
||||||
$parseMode = 0;
|
|
||||||
if ( $msg =~ /^markdown(.*)$/is ) {
|
|
||||||
$msg = $1;
|
|
||||||
$parseMode = "Markdown";
|
|
||||||
} elsif ( $msg =~ /^HTML(.*)$/is ) {
|
|
||||||
$msg = $1;
|
|
||||||
$parseMode = "HTML";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$parseMode = 0;
|
|
||||||
}
|
|
||||||
Log3 $name, 4, "TelegramBot_SendIt parseMode $parseMode";
|
|
||||||
|
|
||||||
if ( length($msg) > 1000 ) {
|
if ( length($msg) > 1000 ) {
|
||||||
$hash->{sentMsgText} = substr($msg,0, 1000)."...";
|
$hash->{sentMsgText} = substr($msg,0, 1000)."...";
|
||||||
} else {
|
} else {
|
||||||
$hash->{sentMsgText} = $msg;
|
$hash->{sentMsgText} = $msg;
|
||||||
}
|
}
|
||||||
$msg =~ s/(?<![\\])\\s/ /g;
|
|
||||||
$msg =~ s/(?<![\\])\\n/\x0A/g;
|
$msg = TelegramBot_removeSpecialFormat( $hash, $msg );
|
||||||
$msg =~ s/(?<![\\])\\t/\x09/g;
|
|
||||||
|
|
||||||
# add msg (no file)
|
# add msg (no file)
|
||||||
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "text", undef, $msg, 0 ) if ( ! defined( $ret ) );
|
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "text", undef, $msg, 0 ) if ( ! defined( $ret ) );
|
||||||
@ -1889,10 +1880,16 @@ sub TelegramBot_SendIt($$$$$;$$$)
|
|||||||
|
|
||||||
# add caption
|
# add caption
|
||||||
if ( defined( $addPar ) ) {
|
if ( defined( $addPar ) ) {
|
||||||
$addPar =~ s/(?<![\\])\\n/\x0A/g;
|
my $parseMode = 0;
|
||||||
$addPar =~ s/(?<![\\])\\t/\x09/g;
|
($parseMode, $addPar) = TelegramBot_evalParseMode( $hash, $addPar );
|
||||||
|
|
||||||
|
$addPar = TelegramBot_removeSpecialFormat( $hash, $addPar );
|
||||||
|
|
||||||
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "caption", undef, $addPar, 0 ) if ( ! defined( $ret ) );
|
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "caption", undef, $addPar, 0 ) if ( ! defined( $ret ) );
|
||||||
|
|
||||||
|
# add parseMode
|
||||||
|
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "parse_mode", undef, $parseMode, 0 ) if ( ( ! defined( $ret ) ) && ( $parseMode ) );
|
||||||
|
|
||||||
$addPar = undef;
|
$addPar = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1928,10 +1925,16 @@ sub TelegramBot_SendIt($$$$$;$$$)
|
|||||||
|
|
||||||
# add caption
|
# add caption
|
||||||
if ( defined( $addPar ) ) {
|
if ( defined( $addPar ) ) {
|
||||||
$addPar =~ s/(?<![\\])\\n/\x0A/g;
|
my $parseMode = 0;
|
||||||
$addPar =~ s/(?<![\\])\\t/\x09/g;
|
($parseMode, $addPar) = TelegramBot_evalParseMode( $hash, $addPar );
|
||||||
|
|
||||||
|
$addPar = TelegramBot_removeSpecialFormat( $hash, $addPar );
|
||||||
|
|
||||||
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "caption", undef, $addPar, 0 ) if ( ! defined( $ret ) );
|
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "caption", undef, $addPar, 0 ) if ( ! defined( $ret ) );
|
||||||
|
|
||||||
|
# add parseMode
|
||||||
|
$ret = TelegramBot_AddMultipart($hash, $hash->{HU_DO_PARAMS}, "parse_mode", undef, $parseMode, 0 ) if ( ( ! defined( $ret ) ) && ( $parseMode ) );
|
||||||
|
|
||||||
$addPar = undef;
|
$addPar = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2349,6 +2352,9 @@ sub TelegramBot_Callback($$$)
|
|||||||
if ( defined( $update->{message} ) ) {
|
if ( defined( $update->{message} ) ) {
|
||||||
|
|
||||||
$ret = TelegramBot_ParseMsg( $hash, $update->{update_id}, $update->{message} );
|
$ret = TelegramBot_ParseMsg( $hash, $update->{update_id}, $update->{message} );
|
||||||
|
} elsif ( defined( $update->{edited_message} ) ) {
|
||||||
|
|
||||||
|
$ret = TelegramBot_ParseMsg( $hash, $update->{update_id}, $update->{edited_message} );
|
||||||
} elsif ( defined( $update->{callback_query} ) ) {
|
} elsif ( defined( $update->{callback_query} ) ) {
|
||||||
|
|
||||||
$ret = TelegramBot_ParseCallbackQuery( $hash, $update->{update_id}, $update->{callback_query} );
|
$ret = TelegramBot_ParseCallbackQuery( $hash, $update->{update_id}, $update->{callback_query} );
|
||||||
@ -2403,13 +2409,13 @@ sub TelegramBot_Callback($$$)
|
|||||||
readingsSingleUpdate($hash, "PollingErrCount", $cnt, 1);
|
readingsSingleUpdate($hash, "PollingErrCount", $cnt, 1);
|
||||||
} else {
|
} else {
|
||||||
# Write digest in log on next date
|
# Write digest in log on next date
|
||||||
$doLog = ( $pv ne "3_None" );
|
$doLog = ( $pv ne "0_None" );
|
||||||
readingsSingleUpdate($hash, "PollingErrCount", 1, 1);
|
readingsSingleUpdate($hash, "PollingErrCount", 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif ( substr($now,0,10) ne substr($tst,0,10) ) {
|
} elsif ( substr($now,0,10) ne substr($tst,0,10) ) {
|
||||||
readingsSingleUpdate($hash, "PollingErrCount", 0, 1);
|
readingsSingleUpdate($hash, "PollingErrCount", 0, 1);
|
||||||
$doLog = ( $pv ne "3_None" );
|
$doLog = ( $pv ne "0_None" );
|
||||||
}
|
}
|
||||||
|
|
||||||
# log level is 2 on error if not digest is selected
|
# log level is 2 on error if not digest is selected
|
||||||
@ -2501,9 +2507,15 @@ sub TelegramBot_ParseMsg($$$)
|
|||||||
my $mid = $message->{message_id};
|
my $mid = $message->{message_id};
|
||||||
|
|
||||||
my $from = $message->{from};
|
my $from = $message->{from};
|
||||||
|
if ( ! defined( $from ) ) {
|
||||||
|
Log3 $name, 3, "TelegramBot $name: No from user in message - blocked";
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
my $mpeer = $from->{id};
|
my $mpeer = $from->{id};
|
||||||
|
|
||||||
# ignore if unknown contacts shall be accepter
|
# ignore if unknown contacts shall be accepted
|
||||||
if ( ( AttrVal($name,'allowUnknownContacts',1) == 0 ) && ( ! TelegramBot_IsKnownContact( $hash, $mpeer ) ) ) {
|
if ( ( AttrVal($name,'allowUnknownContacts',1) == 0 ) && ( ! TelegramBot_IsKnownContact( $hash, $mpeer ) ) ) {
|
||||||
my $mName = $from->{first_name};
|
my $mName = $from->{first_name};
|
||||||
$mName .= " ".$from->{last_name} if ( defined($from->{last_name}) );
|
$mName .= " ".$from->{last_name} if ( defined($from->{last_name}) );
|
||||||
@ -2513,19 +2525,22 @@ sub TelegramBot_ParseMsg($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
# check peers beside from only contact (shared contact) and new_chat_participant are checked
|
# check peers beside from only contact (shared contact) and new_chat_participant are checked
|
||||||
|
Log3 $name, 3, "TelegramBot $name: Found from id in message - id : ".$from->{id} if ( TelegramBot_IsKnownContact( $hash, $from->{id} ) );
|
||||||
push( @contacts, $from );
|
push( @contacts, $from );
|
||||||
|
|
||||||
my $chatId = "";
|
my $chatId = "";
|
||||||
my $chat = $message->{chat};
|
my $chat = $message->{chat};
|
||||||
if ( ( defined( $chat ) ) && ( $chat->{type} ne "private" ) ) {
|
if ( ( defined( $chat ) ) && ( $chat->{type} ne "private" ) ) {
|
||||||
|
Log3 $name, 3, "TelegramBot $name: Found chat id in message - id : ".$chat->{id} if ( TelegramBot_IsKnownContact( $hash, $chat->{id} ) );
|
||||||
push( @contacts, $chat );
|
push( @contacts, $chat );
|
||||||
$chatId = $chat->{id};
|
$chatId = $chat->{id};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $user = $message->{new_chat_participant};
|
# new chat participant has been removed and replaced with new_chat_members
|
||||||
if ( defined( $user ) ) {
|
# my $user = $message->{new_chat_participant};
|
||||||
push( @contacts, $user );
|
# if ( defined( $user ) ) {
|
||||||
}
|
# push( @contacts, $user );
|
||||||
|
# }
|
||||||
|
|
||||||
# get reply message id
|
# get reply message id
|
||||||
my $replyId;
|
my $replyId;
|
||||||
@ -2722,7 +2737,6 @@ sub TelegramBot_ParseChannelPost($$$)
|
|||||||
|
|
||||||
my $mpeer = $chatId;
|
my $mpeer = $chatId;
|
||||||
|
|
||||||
|
|
||||||
# ignore if unknown contacts shall be accepter
|
# ignore if unknown contacts shall be accepter
|
||||||
if ( ( AttrVal($name,'allowUnknownContacts',1) == 0 ) && ( ! TelegramBot_IsKnownContact( $hash, $chatId ) ) ) {
|
if ( ( AttrVal($name,'allowUnknownContacts',1) == 0 ) && ( ! TelegramBot_IsKnownContact( $hash, $chatId ) ) ) {
|
||||||
my $mName = $chat->{title};
|
my $mName = $chat->{title};
|
||||||
@ -2731,6 +2745,7 @@ sub TelegramBot_ParseChannelPost($$$)
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log3 $name, 3, "TelegramBot $name: Found chat id in channel - id : ".$chat->{id} if ( TelegramBot_IsKnownContact( $hash, $chat->{id} ) );
|
||||||
push( @contacts, $chat );
|
push( @contacts, $chat );
|
||||||
|
|
||||||
|
|
||||||
@ -2950,6 +2965,7 @@ sub TelegramBot_ParseCallbackQuery($$$)
|
|||||||
$mpeernorm =~ s/ /_/g;
|
$mpeernorm =~ s/ /_/g;
|
||||||
|
|
||||||
# check peers beside from only contact (shared contact) and new_chat_participant are checked
|
# check peers beside from only contact (shared contact) and new_chat_participant are checked
|
||||||
|
Log3 $name, 3, "TelegramBot $name: Found from id in callback - id : ".$from->{id} if ( TelegramBot_IsKnownContact( $hash, $from->{id} ) );
|
||||||
push( @contacts, $from );
|
push( @contacts, $from );
|
||||||
|
|
||||||
my $answerData = "";
|
my $answerData = "";
|
||||||
@ -3516,6 +3532,9 @@ sub TelegramBot_checkAllowedPeer($$$) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# stores Telegram API Token
|
# stores Telegram API Token
|
||||||
sub TelegramBot_getBaseURL($)
|
sub TelegramBot_getBaseURL($)
|
||||||
@ -3622,6 +3641,53 @@ sub TelegramBot_AttrNum($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
######################################
|
||||||
|
# parseMode either from attr or from prefix to message
|
||||||
|
# returns parseMode and msg as tupel
|
||||||
|
sub TelegramBot_evalParseMode($$) {
|
||||||
|
my ($hash, $msg) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $parseMode = TelegramBot_AttrNum($name,"parseModeSend","0" );
|
||||||
|
if ( $parseMode == 1 ) {
|
||||||
|
$parseMode = "Markdown";
|
||||||
|
} elsif ( $parseMode == 2 ) {
|
||||||
|
$parseMode = "HTML";
|
||||||
|
} elsif ( $parseMode == 3 ) {
|
||||||
|
$parseMode = 0;
|
||||||
|
if ( $msg =~ /^markdown(.*)$/is ) {
|
||||||
|
$msg = $1;
|
||||||
|
$parseMode = "Markdown";
|
||||||
|
} elsif ( $msg =~ /^HTML(.*)$/is ) {
|
||||||
|
$msg = $1;
|
||||||
|
$parseMode = "HTML";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$parseMode = 0;
|
||||||
|
}
|
||||||
|
Log3 $name, 4, "TelegramBot_SendIt parseMode $parseMode";
|
||||||
|
|
||||||
|
return ($parseMode,$msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
######################################
|
||||||
|
# remove / replace double separators, line feed and tabs
|
||||||
|
sub TelegramBot_removeSpecialFormat($$) {
|
||||||
|
my ($hash, $msg) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
$msg =~ s/(?<![\\])\\s/ /g;
|
||||||
|
$msg =~ s/(?<![\\])\\n/\x0A/g;
|
||||||
|
$msg =~ s/(?<![\\])\\t/\x09/g;
|
||||||
|
|
||||||
|
return $msg
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
# Get a string and identify possible media streams
|
# Get a string and identify possible media streams
|
||||||
# PNG is tested
|
# PNG is tested
|
||||||
|
Loading…
x
Reference in New Issue
Block a user