From 96ee9d481ee11666723d86facfb8832b0b00b1dc Mon Sep 17 00:00:00 2001
From: viegener <>
Date: Thu, 23 May 2019 07:51:03 +0000
Subject: [PATCH] 50_TelegramBot: allow \s, addtl silenCmds, fixes
git-svn-id: https://svn.fhem.de/fhem/trunk@19451 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/50_TelegramBot.pm | 35 +++++++++++++++++++++++++----------
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index f055f764f..ae0c96782 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: allow \s, addtl silenCmds, fixes
- change: 55_PIFACE: Now wiringPi V2.46 is supported. Various optimizations
- feature: 73_DoorBird: Automatic snapshots at events with path as Reading
- bugfix: 73_AutoShuttersControl: expand shading out drives, fix commandref
diff --git a/fhem/FHEM/50_TelegramBot.pm b/fhem/FHEM/50_TelegramBot.pm
index d4f8dd569..8acc572ff 100644
--- a/fhem/FHEM/50_TelegramBot.pm
+++ b/fhem/FHEM/50_TelegramBot.pm
@@ -161,11 +161,19 @@
# Allow caption in sendImage also with \n\t
# 2.8 2018-03-11 more silent cmds, caption formatting, several fixes
+# Pull request: silentDocument, silentLocation, silentVoice
+# Corrections for single peer not needed for sent command
+# single peer limited for reply and other change messages
+# Allow \s for space in message (allows multiple spaces in preformatted messages)
+# Document \n \t \s in messages
+# Corrected Eol
+# 2.9 2019-05-23 allow \s, addtl silenCmds, fixes
+
#
##############################################################################
# TASKS
+# Restructure help in logical blocks
#
-# additional silent commands
#
# queryDialogStart / queryDialogEnd - keep msg id
#
@@ -175,7 +183,6 @@
#
# replyKeyboardRemove - #msg592808
#
-# \n in inline keyboards - not possible currently
#
##############################################################################
@@ -231,6 +238,9 @@ my %sets = (
"silentmsg" => "textField",
"silentImage" => "textField",
"silentInline" => "textField",
+ "silentDocument" => "textField",
+ "silentLocation" => "textField",
+ "silentVoice" => "textField",
"msgDelete" => "textField",
@@ -493,7 +503,7 @@ sub TelegramBot_Set($@)
if( ($cmd eq 'message') || ($cmd eq 'queryInline') || ($cmd eq 'queryEditInline') || ($cmd eq 'queryAnswer') ||
($cmd eq 'msg') || ($cmd eq '_msg') || ($cmd eq 'reply') || ($cmd eq 'msgEdit') || ($cmd eq 'msgForceReply') ||
- ($cmd eq 'silentmsg') || ($cmd eq 'silentImage') || ($cmd eq 'silentInline') || ($cmd =~ /^send.*/ ) ) {
+ ($cmd =~ /^silent.*/ ) || ($cmd =~ /^send.*/ ) ) {
my $msgid;
my $msg;
@@ -503,6 +513,7 @@ sub TelegramBot_Set($@)
my $peers;
my $inline = 0;
my $needspeer = 1;
+ my $singlepeer = 0;
if ( ($cmd eq 'reply') || ($cmd eq 'msgEdit' ) || ($cmd eq 'queryEditInline' ) ) {
return "TelegramBot_Set: Command $cmd, no msgid and no text/file specified" if ( $numberOfArgs < 3 );
@@ -510,6 +521,8 @@ sub TelegramBot_Set($@)
return "TelegramBot_Set: Command $cmd, msgId must be given as first parameter before peer" if ( $msgid =~ /^@/ );
$numberOfArgs--;
# all three messages need also a peer/chat_id
+ # but only a single peer is needed
+ $singlepeer = 1;
} elsif ($cmd eq 'queryAnswer') {
$needspeer = 0;
}
@@ -517,7 +530,7 @@ sub TelegramBot_Set($@)
# special options
$inline = 1 if ( ($cmd eq 'queryInline') || ($cmd eq 'queryEditInline') || ($cmd eq 'silentInline') );
$options .= " -force_reply- " if ($cmd eq 'msgForceReply');
- $options .= " -silent- " if ( ($cmd eq 'silentmsg') || ($cmd eq 'silentImage') || ($cmd eq 'silentInline') ) ;
+ $options .= " -silent- " if ( ($cmd =~ /^silent.*/ ) ) ;
return "TelegramBot_Set: Command $cmd, no peers and no text/file specified" if ( $numberOfArgs < 2 );
@@ -525,7 +538,7 @@ sub TelegramBot_Set($@)
while ( $args[0] =~ /^@(..+)$/ ) {
my $ppart = $1;
- return "TelegramBot_Set: Command $cmd, need exactly one peer" if ( ($cmd eq 'reply') && ( defined( $peers ) ) );
+ return "TelegramBot_Set: Command $cmd, need exactly one peer" if ( ($singlepeer) && ( defined( $peers ) ) );
$peers .= " " if ( defined( $peers ) );
$peers = "" if ( ! defined( $peers ) );
$peers .= $ppart;
@@ -545,13 +558,13 @@ sub TelegramBot_Set($@)
}
if ( ($cmd eq 'sendPhoto') || ($cmd eq 'sendImage') || ($cmd eq 'image') || ($cmd eq 'silentImage') ) {
$sendType = 1;
- } elsif ($cmd eq 'sendVoice') {
+ } elsif ( ($cmd eq 'sendVoice') || ($cmd eq 'silentVoice') ) {
$sendType = 2;
- } elsif ( ($cmd eq 'sendDocument') || ($cmd eq 'sendMedia') ) {
+ } elsif ( ($cmd eq 'sendDocument') || ($cmd eq 'sendMedia') || ($cmd eq 'silentDocument') ) {
$sendType = 3;
} elsif ( ($cmd eq 'msgEdit') || ($cmd eq 'queryEditInline') ) {
$sendType = 10;
- } elsif ($cmd eq 'sendLocation') {
+ } elsif ( ($cmd eq 'sendLocation') || ($cmd eq 'silentLocation') ) {
$sendType = 11;
} elsif ($cmd eq 'queryAnswer') {
$sendType = 12;
@@ -661,7 +674,6 @@ sub TelegramBot_Set($@)
my $peers;
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;
@@ -1783,6 +1795,7 @@ sub TelegramBot_SendIt($$$$$;$$$)
} else {
$hash->{sentMsgText} = $msg;
}
+ $msg =~ s/(?message|msg|_msg|send [ @<peer1> ... @<peerN> ] [ (<keyrow1>) ... (<keyrowN>) ] <text>
Sends the given message to the given peer or if peer(s) is ommitted currently defined default peer user. Each peer given needs to be always prefixed with a '@'. Peers can be specified as contact ids, full names (with underscore instead of space), usernames (prefixed with another @) or chat names (also known as groups in telegram groups must be prefixed with #). Multiple peers are to be separated by space
A reply keyboard can be specified by adding a list of strings enclosed in parentheses "()". Each separate string will make one keyboard row in a reply keyboard. The different keys in the row need to be separated by |. The key strings can contain spaces.
Messages do not need to be quoted if containing spaces. If you want to use parentheses at the start of the message than add one extra character before the parentheses (i.e. an underline) to avoid the message being parsed as a keyboard
+ Messages can also contain special characters for the message. These include newline =\n, tab = \t and also a normal space = \s
+
Examples:
set aTelegramBotDevice message @@someusername a message to be sent
silentmsg, silentImage, silentInline ...
silentmsg, silentImage, silentDocument, silentLocation, silentVoice , silentInline ...
msgForceReply [ @<peer1> ... @<peerN> ] <text>