telegram-bot-bash/bin/send_message.sh

74 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2020-12-18 13:53:44 +00:00
#!/bin/bash
2021-01-21 08:22:14 +00:00
# shellcheck disable=SC1090,SC2034
2020-12-16 12:45:59 +00:00
#===============================================================================
#
2020-12-24 10:41:40 +00:00
# FILE: bin/send_message.sh
2020-12-16 12:45:59 +00:00
#
2021-01-09 21:14:44 +00:00
USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]'
2020-12-16 12:45:59 +00:00
#
# DESCRIPTION: send a message to the given user/group
#
# OPTIONS: format - normal, markdown, html, stdin, - (optional)
# CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
2020-12-16 12:45:59 +00:00
# message - message to send in specified format
# if no format is givern send_message() format is used
#
# use format "stdin" to read message from stdin or from a file:
# send_message.sh stdin "CHAT[ID]" <file
# df -h | send_message.sh - "CHAT[ID]"
#
2020-12-16 12:45:59 +00:00
# -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
2020-12-18 13:53:44 +00:00
# CREATED: 16.12.2020 11:34
2020-12-16 12:45:59 +00:00
#
2022-06-27 18:18:58 +00:00
#### $$VERSION$$ v1.52-1-g0dae2db
2020-12-16 12:45:59 +00:00
#===============================================================================
2020-12-18 13:53:44 +00:00
####
2020-12-16 12:45:59 +00:00
# parse args
SEND="send_message"
case "$1" in
2021-01-07 12:15:18 +00:00
"nor"*|"tex"*)
2020-12-16 12:45:59 +00:00
SEND="send_normal_message"
shift
;;
"mark"*)
SEND="send_markdownv2_message"
shift
;;
"html")
SEND="send_html_message"
shift
;;
"stdin"|"-")
FILE="stdin"
shift
;;
2020-12-16 12:45:59 +00:00
esac
# set bashbot environment
source "${0%/*}/bashbot_env.inc.sh" "${3:-debug}" # $3 debug
2021-01-21 08:22:14 +00:00
print_help "$1"
2020-12-18 13:53:44 +00:00
####
# ready, do stuff here -----
if [ "$1" == "BOTADMIN" ]; then
2021-03-03 12:40:51 +00:00
CHAT="${BOTADMIN}"
else
CHAT="$1"
fi
2020-12-18 13:53:44 +00:00
# send message in selected format
if [ "${FILE}" = "stdin" ]; then
"${SEND}" "${CHAT}" "$(cat)"
else
"${SEND}" "${CHAT}" "$2"
fi
2020-12-18 13:53:44 +00:00
# output send message result
2021-01-21 08:22:14 +00:00
print_result