mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 00:37:34 +00:00
add bin/send_file.sh, fix logging caption
This commit is contained in:
parent
88d1de2009
commit
2ab00a2c57
@ -11,7 +11,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v1.2-dev2-74-g0b7cd8a
|
||||
#### $$VERSION$$ v1.2-dev2-77-g88d1de2
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 success (hopefully)
|
||||
@ -488,7 +488,7 @@ if detect_curl ; then
|
||||
[ "$#" -lt 4 ] && return
|
||||
if [ -n "$5" ]; then
|
||||
[ -n "${BASHBOTDEBUG}" ] &&\
|
||||
log_update "sendUpload CHAT=${1} WHAT=${2} FILE=${3} CAPT=${4}"
|
||||
log_update "sendUpload CHAT=${1} WHAT=${2} FILE=${3} CAPT=${5}"
|
||||
# shellcheck disable=SC2086
|
||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -b -n 2>/dev/null )"
|
||||
|
@ -13,12 +13,12 @@
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 18.12.2020 12:27
|
||||
#
|
||||
#### $$VERSION$$ v1.2-dev2-75-gf016598
|
||||
#### $$VERSION$$ v1.2-dev2-77-g88d1de2
|
||||
#===============================================================================
|
||||
|
||||
############
|
||||
# set where your bashbot lives
|
||||
export BASHBOT_HOME BASHBOT_ETC BASHBOT_VAR
|
||||
export BASHBOT_HOME BASHBOT_ETC BASHBOT_VAR FILE_REGEX
|
||||
|
||||
# default: one dir up
|
||||
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
|
||||
@ -26,8 +26,8 @@ BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
|
||||
|
||||
# set you own BASHBOT_HOME if different, e.g.
|
||||
# BASHBOT_HOME="/usr/local/telegram-bot-bash"
|
||||
BASHBOT_ETC="${BASHBOT_HOME}"
|
||||
BASHBOT_VAR="${BASHBOT_HOME}"
|
||||
BASHBOT_ETC="${BASHBOT_HOME}"
|
||||
|
||||
#####
|
||||
# if files are not readable, eviroment is wrong or bashbot is not initialized
|
||||
@ -41,6 +41,10 @@ else
|
||||
source "${BASHBOT_HOME}/bashbot.sh" source "$1"
|
||||
fi
|
||||
|
||||
# overwrite bot FILE regex to BASHBOT_ETC
|
||||
# change this to the location you want to allow file uploads from
|
||||
FILE_REGEX="${BASHBOT_ETC%/bin*}/.*"
|
||||
|
||||
# check for botconfig.jssh readable
|
||||
if [ ! -r "${BASHBOT_ETC}/botconfig.jssh" ]; then
|
||||
echo "Bashbot config file in \"${BASHBOT_ETC}\" does not exist or is not readable."
|
||||
|
65
bin/send_file.sh
Executable file
65
bin/send_file.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: bin/send_file.sh
|
||||
#
|
||||
# USAGE: send_file.sh [-h|--help] "CHAT[ID]" "file" "caption ...." [debug]
|
||||
#
|
||||
# DESCRIPTION: send a file to the given user/group
|
||||
#
|
||||
# OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
|
||||
# file - file to send, must be an absolute path or relative to pwd
|
||||
# Note: must not contain .. or . and located below BASHBOT_ETC
|
||||
# caption - message to send with file
|
||||
#
|
||||
# -h - display short help
|
||||
# --help - this help
|
||||
#
|
||||
# Set BASHBOT_HOME to your installation directory
|
||||
#
|
||||
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 25.12.2020 20:24
|
||||
#
|
||||
#### $$VERSION$$ v1.2-dev2-77-g88d1de2
|
||||
#===============================================================================
|
||||
|
||||
|
||||
####
|
||||
# parse args
|
||||
SEND="upload_file"
|
||||
case "$1" in
|
||||
'')
|
||||
echo "missing arguments"
|
||||
;&
|
||||
"-h"*)
|
||||
echo 'usage: send_file [-h|--help] "CHAT[ID]" "file" "caption ...." [debug]'
|
||||
exit 1
|
||||
;;
|
||||
'--h'*)
|
||||
sed -n '3,/###/p' <"$0"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# set bashbot environment
|
||||
# shellcheck disable=SC1090
|
||||
source "${0%/*}/bashbot_env.inc.sh" "$4" # $4 debug
|
||||
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
||||
FILE="$2"
|
||||
[[ "$2" != "/"* ]] && FILE="${PWD}/$2"
|
||||
|
||||
# send message in selected format
|
||||
"${SEND}" "${CHAT}" "${FILE}" "$3"
|
||||
|
||||
# output send message result
|
||||
jssh_printDB "BOTSENT" | sort -r
|
||||
|
@ -33,6 +33,7 @@ Have FUN!
|
||||
│ ├── send_message.sh # send message to given chat
|
||||
│ ├── edit_message.sh # replace given message id in given chat
|
||||
│ ├── send_broadcast.sh # send message to all known chats
|
||||
│ ├── send_file.sh # send file to given chat
|
||||
│ ├── bashbot_stats.sh # does what it says ...
|
||||
│ │
|
||||
│ └── bashbot_env.inc.sh # bashbot location included from scripts, adapt if needed
|
||||
@ -122,6 +123,15 @@ bin/send_edit_message.sh "CHAT[ID]" "12345" "Done!"
|
||||
["ID"] "12345"
|
||||
```
|
||||
|
||||
To send a file to one user or chat run the following command:
|
||||
|
||||
```bash
|
||||
bin/send_file.sh "CHAT[ID]" "funny-pic.jpg" "enjoy this picture"
|
||||
|
||||
["OK"] "true"
|
||||
["ID"] "12346"
|
||||
```
|
||||
|
||||
Note: to get help about a script in bin/ run `scriptname.sh --help`
|
||||
|
||||
----
|
||||
@ -330,5 +340,5 @@ send_action "${CHAT[ID]}" "action"
|
||||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v1.2-dev2-71-gdca7a6d
|
||||
#### $$VERSION$$ v1.2-dev2-77-g88d1de2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user