2019-05-12 15:51:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# file: modules/message.sh
|
|
|
|
# do not edit, this file will be overwritten on update
|
|
|
|
|
|
|
|
# This file is public domain in the USA and all free countries.
|
|
|
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
|
|
|
#
|
2020-11-29 14:34:00 +00:00
|
|
|
# shellcheck disable=SC1117
|
2021-02-07 16:05:34 +00:00
|
|
|
#### $$VERSION$$ v1.45-dev-3-g429c230
|
2020-06-14 18:56:46 +00:00
|
|
|
|
|
|
|
# will be automatically sourced from bashbot
|
2020-05-14 17:47:37 +00:00
|
|
|
|
|
|
|
# source once magic, function named like file
|
|
|
|
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
2019-05-12 15:51:52 +00:00
|
|
|
|
|
|
|
# source from commands.sh to use the sendMessage functions
|
|
|
|
|
2021-01-04 22:08:09 +00:00
|
|
|
MSG_URL=${URL}'/sendMessage'
|
|
|
|
EDIT_URL=${URL}'/editMessageText'
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2020-12-13 15:23:03 +00:00
|
|
|
#
|
|
|
|
# send/edit message variants ------------------
|
|
|
|
#
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 message
|
2019-05-12 15:51:52 +00:00
|
|
|
send_normal_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
local len text; text="$(JsonEscape "$2")"
|
2020-12-13 16:19:52 +00:00
|
|
|
until [ -z "${text}" ]; do
|
|
|
|
if [ "${#text}" -le 4096 ]; then
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" '"text":"'"${text}"'"' "${MSG_URL}"
|
2020-12-13 16:19:52 +00:00
|
|
|
break
|
|
|
|
else
|
|
|
|
len=4095
|
|
|
|
[ "${text:4095:2}" != "\n" ] &&\
|
|
|
|
len="${text:0:4096}" && len="${len%\\n*}" && len="${#len}"
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" '"text":"'"${text:0:${len}}"'"' "${MSG_URL}"
|
2020-12-13 16:19:52 +00:00
|
|
|
text="${text:$((len+2))}"
|
|
|
|
fi
|
|
|
|
done
|
2020-12-13 15:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 CHAT $2 message
|
|
|
|
send_markdown_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_format_message_url "$1" "$2" ',"parse_mode":"markdown"' "${MSG_URL}"
|
2020-12-13 15:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 CHAT $2 message
|
|
|
|
send_markdownv2_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_markdownv2_message_url "$1" "$2" ',"parse_mode":"markdownv2"' "${MSG_URL}"
|
2020-12-13 15:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 CHAT $2 message
|
|
|
|
send_html_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_format_message_url "$1" "$2" ',"parse_mode":"html"' "${MSG_URL}"
|
2020-12-13 15:23:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 16:19:52 +00:00
|
|
|
# $1 CHAT $2 msg-id $3 message
|
|
|
|
edit_normal_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_format_message_url "$1" "$3" ',"message_id":'"$2"'' "${EDIT_URL}"
|
2020-12-13 16:19:52 +00:00
|
|
|
}
|
2020-12-13 15:23:03 +00:00
|
|
|
|
2020-12-13 16:25:44 +00:00
|
|
|
# $1 CHAT $2 msg-id $3 message
|
2020-12-13 16:19:52 +00:00
|
|
|
edit_markdown_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdown"' "${EDIT_URL}"
|
2020-12-13 16:19:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 16:25:44 +00:00
|
|
|
# $1 CHAT $2 msg-id $3 message
|
2020-12-13 16:19:52 +00:00
|
|
|
edit_markdownv2_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_markdownv2_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"markdownv2"' "${EDIT_URL}"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 16:25:44 +00:00
|
|
|
# $1 CHAT $2 msg-id $3 message
|
2020-12-13 16:19:52 +00:00
|
|
|
edit_html_message() {
|
2021-01-05 15:17:34 +00:00
|
|
|
_format_message_url "$1" "$3" ',"message_id":'"$2"',"parse_mode":"html"' "${EDIT_URL}"
|
2020-12-13 16:19:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 17:50:45 +00:00
|
|
|
# $1 chat $2 mesage_id, $3 caption
|
|
|
|
edit_message_caption() {
|
2021-01-15 11:40:08 +00:00
|
|
|
sendJson "$1" '"message_id":'"$2"',"caption":"'"$3"'"' "${URL}/editMessageCaption"
|
2021-01-14 17:50:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 16:19:52 +00:00
|
|
|
|
2020-12-13 15:23:03 +00:00
|
|
|
# internal function, send/edit formatted message with parse_mode and URL
|
2020-12-13 16:19:52 +00:00
|
|
|
# $1 CHAT $2 message $3 action $4 URL
|
2020-12-13 17:25:46 +00:00
|
|
|
_format_message_url(){
|
2021-01-05 15:17:34 +00:00
|
|
|
local text; text="$(JsonEscape "$2")"
|
2020-12-13 15:23:03 +00:00
|
|
|
[ "${#text}" -ge 4096 ] && log_error "Warning: html/markdown message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
|
2020-05-20 13:18:23 +00:00
|
|
|
until [ -z "${text}" ]; do
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" '"text":"'"${text:0:4096}"'"'"$3"'' "$4"
|
2020-05-20 13:18:23 +00:00
|
|
|
text="${text:4096}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-12-13 15:23:03 +00:00
|
|
|
# internal function, send/edit markdownv2 message with URL
|
2020-12-13 16:19:52 +00:00
|
|
|
# $1 CHAT $2 message $3 action $4 URL
|
2020-12-13 15:23:03 +00:00
|
|
|
_markdownv2_message_url() {
|
2021-01-05 15:17:34 +00:00
|
|
|
local text; text="$(JsonEscape "$2")"
|
2020-12-13 15:23:03 +00:00
|
|
|
[ "${#text}" -ge 4096 ] && log_error "Warning: markdownv2 message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
|
2020-05-20 13:18:23 +00:00
|
|
|
# markdown v2 needs additional double escaping!
|
2021-01-04 22:08:09 +00:00
|
|
|
text="$(sed -E -e 's|([_|~`>+=#{}()!.-])|\\\1|g' <<< "${text}")"
|
2019-05-12 15:51:52 +00:00
|
|
|
until [ -z "${text}" ]; do
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" '"text":"'"${text:0:4096}"'"'"$3"'' "$4"
|
2019-05-12 15:51:52 +00:00
|
|
|
text="${text:4096}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-12-13 15:23:03 +00:00
|
|
|
#
|
|
|
|
# send keyboard, buttons, files ---------------
|
|
|
|
#
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 message $3 keyboard
|
2019-05-12 15:51:52 +00:00
|
|
|
send_keyboard() {
|
|
|
|
if [[ "$3" != *'['* ]]; then old_send_keyboard "${@}"; return; fi
|
2020-08-15 07:47:16 +00:00
|
|
|
local text='"text":"'"Keyboard:"'"'
|
2021-01-05 15:17:34 +00:00
|
|
|
if [ -n "$2" ]; then
|
|
|
|
text="$(JsonEscape "$2")"
|
2020-08-15 07:47:16 +00:00
|
|
|
text='"text":"'"${text//$'\n'/\\n}"'"'
|
|
|
|
fi
|
2020-05-14 18:33:30 +00:00
|
|
|
local one_time=', "one_time_keyboard":true' && [ -n "$4" ] && one_time=""
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" "${text}"', "reply_markup": {"keyboard": [ '"$3"' ] '"${one_time}"'}' "${MSG_URL}"
|
|
|
|
# '"text":"$2", "reply_markup": {"keyboard": [ $3 ], "one_time_keyboard": true}'
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 message $3 remove
|
2019-05-12 15:51:52 +00:00
|
|
|
remove_keyboard() {
|
2020-08-15 07:47:16 +00:00
|
|
|
local text='"text":"'"remove custom keyboard ..."'"'
|
2021-01-05 15:17:34 +00:00
|
|
|
if [ -n "$2" ]; then
|
|
|
|
text="$(JsonEscape "$2")"
|
2020-08-15 07:47:16 +00:00
|
|
|
text='"text":"'"${text//$'\n'/\\n}"'"'
|
|
|
|
fi
|
2021-01-05 15:17:34 +00:00
|
|
|
sendJson "$1" "${text}"', "reply_markup": {"remove_keyboard":true}' "${MSG_URL}"
|
2020-08-15 07:47:16 +00:00
|
|
|
# delete message if no message or $3 not empty
|
2021-01-05 15:17:34 +00:00
|
|
|
[[ -z "$2" || -n "$3" ]] && delete_message "$1" "${BOTSENT[ID]}" "nolog"
|
2019-05-12 15:51:52 +00:00
|
|
|
#JSON='"text":"$2", "reply_markup": {"remove_keyboard":true}'
|
|
|
|
}
|
2020-08-15 07:47:16 +00:00
|
|
|
|
2021-01-26 19:49:55 +00:00
|
|
|
# buttons will specified as "texts
|
|
|
|
#|url" ... "text|url" empty arg starts new row
|
|
|
|
# url not starting with http:// or https:// will be send as callback_data
|
|
|
|
send_inline_buttons(){
|
|
|
|
send_inline_keyboard "$1" "$2" "$(_button_row "${@:3}")"
|
2021-01-22 07:11:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 19:49:55 +00:00
|
|
|
# $1 CHAT $2 message-id $3 buttons
|
|
|
|
# buttons will specified as "text|url" ... "text|url" empty arg starts new row
|
|
|
|
# url not starting with http:// or https:// will be send as callback_data
|
|
|
|
edit_inline_buttons(){
|
|
|
|
edit_inline_keyboard "$1" "$2" "$(_button_row "${@:3}")"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
2021-01-19 21:56:58 +00:00
|
|
|
|
|
|
|
|
2021-01-19 22:22:38 +00:00
|
|
|
# $1 CHAT $2 message $3 button text $4 button url
|
2019-05-12 15:51:52 +00:00
|
|
|
send_button() {
|
2021-01-19 22:22:38 +00:00
|
|
|
send_inline_keyboard "$1" "$2" '[{"text":"'"$(JsonEscape "$3")"'", "url":"'"$4"'"}]'
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 22:18:26 +00:00
|
|
|
# helper function to create json for a button row
|
2021-01-19 22:53:58 +00:00
|
|
|
# buttons will specified as "text|url" ... "text|url" empty arg starts new row
|
2021-01-24 11:30:56 +00:00
|
|
|
# url not starting with http:// or https:// will be send as callback_data
|
2021-01-19 22:18:26 +00:00
|
|
|
_button_row() {
|
|
|
|
[ -z "$1" ] && return 1
|
2021-01-24 11:30:56 +00:00
|
|
|
local arg type json sep
|
2021-01-19 22:18:26 +00:00
|
|
|
for arg in "$@"
|
|
|
|
do
|
2021-01-19 22:53:58 +00:00
|
|
|
[ -z "${arg}" ] && sep="],[" && continue
|
2021-01-24 11:30:56 +00:00
|
|
|
type="callback_data"
|
2021-01-24 12:52:44 +00:00
|
|
|
[[ "${arg##*|}" =~ ^(https*://|tg://) ]] && type="url"
|
2021-01-24 11:30:56 +00:00
|
|
|
json+="${sep}"'{"text":"'"$(JsonEscape "${arg%|*}")"'", "'"${type}"'":"'"${arg##*|}"'"}'
|
2021-01-19 22:53:58 +00:00
|
|
|
sep=","
|
2021-01-19 22:18:26 +00:00
|
|
|
done
|
|
|
|
printf "[%s]" "${json}"
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:49:55 +00:00
|
|
|
# raw inline functions, for special use
|
|
|
|
# $1 CHAT $2 message-id $3 keyboard
|
|
|
|
edit_inline_keyboard() {
|
|
|
|
sendJson "$1" '"message_id":'"$2"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${URL}/editMessageReplyMarkup"
|
|
|
|
# JSON='"message_id":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# $1 CHAT $2 message $3 keyboard
|
|
|
|
send_inline_keyboard() {
|
|
|
|
local text; text='"text":"'$(JsonEscape "$2")'"'; [ -z "$2" ] && text='"text":"..."'
|
|
|
|
sendJson "$1" "${text}"', "reply_markup": {"inline_keyboard": [ '"$3"' ]}' "${MSG_URL}"
|
|
|
|
# JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}'
|
|
|
|
}
|
|
|
|
|
2021-01-26 13:51:50 +00:00
|
|
|
# $1 callback id, $2 text to show, alert if not empty
|
2021-01-26 13:38:31 +00:00
|
|
|
answer_callback_query() {
|
|
|
|
local alert
|
|
|
|
[ -n "$3" ] && alert='","show_alert": true'
|
|
|
|
sendJson "" '"callback_query_id": "'"$1"'","text":"'"$2${alert}"'"' "${URL}/answerCallbackQuery"
|
|
|
|
}
|
|
|
|
|
2021-01-14 17:25:53 +00:00
|
|
|
# $1 chat, $2 file_id on telegram server
|
|
|
|
send_sticker() {
|
2021-01-14 18:49:01 +00:00
|
|
|
sendJson "$1" '"sticker": "'"$2"'"' "${URL}/sendSticker"
|
2021-01-14 17:25:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2021-01-14 17:31:39 +00:00
|
|
|
# only curl can send files ...
|
|
|
|
if detect_curl ; then
|
|
|
|
# there are no checks if URL or ID exists
|
|
|
|
# $1 chat $3 ... $n URL or ID
|
2020-06-26 06:26:52 +00:00
|
|
|
send_album(){
|
2021-01-05 15:17:34 +00:00
|
|
|
[ -z "$1" ] && return 1
|
2021-01-20 18:50:19 +00:00
|
|
|
[ -z "$3" ] && return 2 # minimum 2 files
|
2021-01-05 15:17:34 +00:00
|
|
|
local CHAT JSON IMAGE; CHAT="$1"; shift
|
2020-06-26 06:26:52 +00:00
|
|
|
for IMAGE in "$@"
|
|
|
|
do
|
|
|
|
[ -n "${JSON}" ] && JSON+=","
|
|
|
|
JSON+='{"type":"photo","media":"'${IMAGE}'"}'
|
|
|
|
done
|
|
|
|
# shellcheck disable=SC2086
|
2021-01-10 22:17:35 +00:00
|
|
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "${URL}/sendMediaGroup" -F "chat_id=${CHAT}"\
|
2020-06-26 06:26:52 +00:00
|
|
|
-F "media=[${JSON}]" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
|
|
|
sendJsonResult "${res}" "send_album (curl)" "${CHAT}" "$@"
|
|
|
|
[[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" &
|
|
|
|
}
|
|
|
|
else
|
|
|
|
send_album(){
|
2021-01-14 17:31:39 +00:00
|
|
|
log_error "Sorry, wget Album upload not implemented"
|
2020-06-26 06:26:52 +00:00
|
|
|
BOTSENT[OK]="false"
|
|
|
|
[[ -z "${SOURCE}" && -n "${BASHBOT_EVENT_SEND[*]}" ]] && event_send "album" "$@" &
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2020-12-28 12:09:28 +00:00
|
|
|
UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}"
|
|
|
|
|
2021-01-06 16:45:13 +00:00
|
|
|
# supports local file, URL and file_id
|
|
|
|
# $1 chat, $2 file https::// file_id:// , $3 caption, $4 extension (optional)
|
|
|
|
send_file(){
|
2021-01-16 09:47:18 +00:00
|
|
|
local url what num stat err media capt file="$2" ext="$4"
|
2021-01-06 17:32:53 +00:00
|
|
|
capt="$(JsonEscape "$3")"
|
2021-01-05 21:01:32 +00:00
|
|
|
if [[ "${file}" =~ ^https*:// ]]; then
|
|
|
|
media="URL"
|
2021-01-06 15:43:18 +00:00
|
|
|
elif [[ "${file}" == file_id://* ]]; then
|
|
|
|
media="ID"
|
|
|
|
file="${file#file_id://}"
|
2019-05-13 10:47:03 +00:00
|
|
|
else
|
2021-01-05 21:01:32 +00:00
|
|
|
# we have a file, check file location ...
|
|
|
|
media="FILE"
|
2021-01-20 18:50:19 +00:00
|
|
|
[[ "${file}" = *'..'* || "${file}" = '.'* ]] && err=1 # no directory traversal
|
2021-01-05 21:01:32 +00:00
|
|
|
if [[ "${file}" = '/'* ]] ; then
|
2021-01-20 18:50:19 +00:00
|
|
|
[[ ! "${file}" =~ ${FILE_REGEX} ]] && err=2 # absolute must match REGEX
|
2021-01-05 21:01:32 +00:00
|
|
|
else
|
2021-01-20 18:50:19 +00:00
|
|
|
file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # others must be in UPLOADDIR
|
2021-01-05 21:01:32 +00:00
|
|
|
fi
|
2021-01-20 18:50:19 +00:00
|
|
|
[ ! -r "${file}" ] && err=3 # and file must exits of course
|
2021-01-06 16:45:13 +00:00
|
|
|
# file path error, generate error response
|
|
|
|
if [ -n "${err}" ]; then
|
|
|
|
BOTSENT=(); BOTSENT[OK]="false"
|
|
|
|
case "${err}" in
|
|
|
|
1) BOTSENT[ERROR]="Path to file $2 contains to much '../' or starts with '.'";;
|
|
|
|
2) BOTSENT[ERROR]="Path to file $2 does not match regex: ${FILE_REGEX} ";;
|
|
|
|
3) if [[ "$2" == "/"* ]];then
|
|
|
|
BOTSENT[ERROR]="File not found: $2"
|
|
|
|
else
|
|
|
|
BOTSENT[ERROR]="File not found: ${UPLOADDIR}/$2"
|
|
|
|
fi;;
|
|
|
|
esac
|
2021-02-07 09:20:09 +00:00
|
|
|
[ -n "${BASHBOTDEBUG}" ] && log_debug "upload_file: CHAT=$1 FILE=$2 MSG=${BOTSENT[ERROR]}"
|
2021-01-06 16:45:13 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
# file OK, let's continue
|
2019-05-13 10:47:03 +00:00
|
|
|
fi
|
2021-01-06 16:45:13 +00:00
|
|
|
|
2021-01-06 15:43:18 +00:00
|
|
|
# no type given, use file ext, if no ext type photo
|
|
|
|
if [ -z "${ext}" ]; then
|
|
|
|
ext="${file##*.}"
|
|
|
|
[ "${ext}" = "${file}" ] && ext="photo"
|
|
|
|
fi
|
2021-01-06 16:45:13 +00:00
|
|
|
# select upload URL
|
2021-01-05 21:01:32 +00:00
|
|
|
case "${ext}" in
|
2021-01-05 21:33:44 +00:00
|
|
|
photo|png|jpg|jpeg|gif|pic)
|
2021-01-16 09:47:18 +00:00
|
|
|
url="${URL}/sendPhoto"; what="photo"; num=",0"; stat="upload_photo"
|
2021-01-10 22:17:35 +00:00
|
|
|
;;
|
|
|
|
audio|mp3|flac)
|
|
|
|
url="${URL}/sendAudio"; what="audio"; stat="upload_audio"
|
2019-05-12 15:51:52 +00:00
|
|
|
;;
|
2021-01-05 21:33:44 +00:00
|
|
|
sticker|webp)
|
2021-01-10 22:17:35 +00:00
|
|
|
url="${URL}/sendSticker"; what="sticker"; stat="upload_photo"
|
2019-05-12 15:51:52 +00:00
|
|
|
;;
|
2021-01-05 21:33:44 +00:00
|
|
|
video|mp4)
|
2021-01-10 22:17:35 +00:00
|
|
|
url="${URL}/sendVideo"; what="video"; stat="upload_video"
|
2019-05-12 15:51:52 +00:00
|
|
|
;;
|
2021-01-05 21:33:44 +00:00
|
|
|
voice|ogg)
|
2021-01-10 22:17:35 +00:00
|
|
|
url="${URL}/sendVoice"; what="voice"; stat="record_audio"
|
2019-05-12 15:51:52 +00:00
|
|
|
;;
|
2021-01-10 22:17:35 +00:00
|
|
|
*) url="${URL}/sendDocument"; what="document"; stat="upload_document"
|
2019-05-12 15:51:52 +00:00
|
|
|
;;
|
|
|
|
esac
|
2021-01-05 21:01:32 +00:00
|
|
|
|
2021-01-06 16:45:13 +00:00
|
|
|
# show file upload to user
|
2021-01-06 17:32:53 +00:00
|
|
|
send_action "$1" "${stat}"
|
2021-01-06 16:45:13 +00:00
|
|
|
# select method to send
|
2021-01-05 21:01:32 +00:00
|
|
|
case "${media}" in
|
|
|
|
FILE) # send local file ...
|
2021-01-06 17:32:53 +00:00
|
|
|
sendUpload "$1" "${what}" "${file}" "${url}" "${capt//\\n/$'\n'}";;
|
2021-01-05 21:01:32 +00:00
|
|
|
|
2021-01-06 16:45:13 +00:00
|
|
|
URL|ID) # send URL, file_id ...
|
2021-01-06 17:32:53 +00:00
|
|
|
sendJson "$1" '"'"${what}"'":"'"${file}"'","caption":"'"${capt//\\n/$'\n'}"'"' "${url}"
|
2021-01-05 21:01:32 +00:00
|
|
|
esac
|
2021-01-06 16:45:13 +00:00
|
|
|
# get file_id and file_type
|
2021-01-06 15:43:18 +00:00
|
|
|
if [ "${BOTSENT[OK]}" = "true" ]; then
|
2021-01-16 09:47:18 +00:00
|
|
|
BOTSENT[FILE_ID]="${UPD["result,${what}${num},file_id"]}"
|
|
|
|
BOTSENT[FILE_TYPE]="${what}"
|
2021-01-06 15:43:18 +00:00
|
|
|
fi
|
2021-01-05 21:01:32 +00:00
|
|
|
return 0
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 16:45:13 +00:00
|
|
|
# $1 typing upload_photo record_video upload_video record_audio upload_audio upload_document find_location
|
2019-05-12 15:51:52 +00:00
|
|
|
send_action() {
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$2" ] && return
|
2021-01-10 22:17:35 +00:00
|
|
|
sendJson "$1" '"action": "'"$2"'"' "${URL}/sendChatAction" &
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 lat $3 long
|
2019-05-12 15:51:52 +00:00
|
|
|
send_location() {
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$3" ] && return
|
2021-01-10 22:17:35 +00:00
|
|
|
sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"'' "${URL}/sendLocation"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 lat $3 long $4 title $5 address $6 foursquard id
|
2019-05-12 15:51:52 +00:00
|
|
|
send_venue() {
|
|
|
|
local add=""
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$5" ] && return
|
|
|
|
[ -n "$6" ] && add=', "foursquare_id": '"$6"''
|
2021-01-10 22:17:35 +00:00
|
|
|
sendJson "$1" '"latitude": '"$2"', "longitude": '"$3"', "address": "'"$5"'", "title": "'"$4"'"'"${add}" "${URL}/sendVenue"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-13 15:23:03 +00:00
|
|
|
#
|
|
|
|
# other send message variants ---------------------------------
|
|
|
|
#
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 from chat $3 from msg id
|
2019-05-12 15:51:52 +00:00
|
|
|
forward_message() {
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$3" ] && return
|
2021-01-10 22:17:35 +00:00
|
|
|
sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/forwardMessage"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
2021-02-07 16:05:34 +00:00
|
|
|
|
|
|
|
# $1 CHAT $2 from chat $3 from msg id
|
|
|
|
copy_message() {
|
|
|
|
[ -z "$3" ] && return
|
|
|
|
sendJson "$1" '"from_chat_id": '"$2"', "message_id": '"$3"'' "${URL}/copyMessage"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 bashbot formatted message, see manual advanced usage
|
2019-05-12 15:51:52 +00:00
|
|
|
send_message() {
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$2" ] && return
|
2019-05-12 15:51:52 +00:00
|
|
|
local text keyboard btext burl no_keyboard file lat long title address sent
|
2021-01-05 15:17:34 +00:00
|
|
|
text="$(sed <<< "$2" 's/ mykeyboardend.*//;s/ *my[kfltab][a-z]\{2,13\}startshere.*//')$(sed <<< "$2" -n '/mytextstartshere/ s/.*mytextstartshere//p')"
|
2020-06-20 11:19:45 +00:00
|
|
|
#shellcheck disable=SC2001
|
2020-12-24 17:20:39 +00:00
|
|
|
text="$(sed <<< "${text}" 's/ *mynewlinestartshere */\n/g')"
|
2020-12-25 19:08:29 +00:00
|
|
|
text="${text//$'\n'/\\n}"
|
2019-05-12 15:51:52 +00:00
|
|
|
[ "$3" != "safe" ] && {
|
2021-01-05 15:17:34 +00:00
|
|
|
no_keyboard="$(sed <<< "$2" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')"
|
|
|
|
keyboard="$(sed <<< "$2" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere *//;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
btext="$(sed <<< "$2" '/mybtextstartshere /!d;s/.*mybtextstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
burl="$(sed <<< "$2" '/myburlstartshere /!d;s/.*myburlstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//g;s/ *mykeyboardendshere.*//g')"
|
|
|
|
file="$(sed <<< "$2" '/myfile[^s]*startshere /!d;s/.*myfile[^s]*startshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
lat="$(sed <<< "$2" '/mylatstartshere /!d;s/.*mylatstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
long="$(sed <<< "$2" '/mylongstartshere /!d;s/.*mylongstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
title="$(sed <<< "$2" '/mytitlestartshere /!d;s/.*mytitlestartshere //;s/ *my[kfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
|
|
|
address="$(sed <<< "$2" '/myaddressstartshere /!d;s/.*myaddressstartshere //;s/ *my[nkfltab][a-z]\{2,13\}startshere.*//;s/ *mykeyboardendshere.*//')"
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ -n "${no_keyboard}" ]; then
|
|
|
|
remove_keyboard "$1" "${text}"
|
2019-05-12 15:51:52 +00:00
|
|
|
sent=y
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ -n "${keyboard}" ]; then
|
2021-01-20 18:50:19 +00:00
|
|
|
if [[ "${keyboard}" != *"["* ]]; then # pre 0.60 style
|
2019-05-12 15:51:52 +00:00
|
|
|
keyboard="[ ${keyboard//\" \"/\" \] , \[ \"} ]"
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
send_keyboard "$1" "${text}" "${keyboard}"
|
2019-05-12 15:51:52 +00:00
|
|
|
sent=y
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ -n "${btext}" ] && [ -n "${burl}" ]; then
|
|
|
|
send_button "$1" "${text}" "${btext}" "${burl}"
|
2019-05-12 15:51:52 +00:00
|
|
|
sent=y
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ -n "${file}" ]; then
|
|
|
|
send_file "$1" "${file}" "${text}"
|
2019-05-12 15:51:52 +00:00
|
|
|
sent=y
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ -n "${lat}" ] && [ -n "${long}" ]; then
|
|
|
|
if [ -n "${address}" ] && [ -n "${title}" ]; then
|
|
|
|
send_venue "$1" "${lat}" "${long}" "${title}" "${address}"
|
2019-05-12 15:51:52 +00:00
|
|
|
else
|
2021-01-04 22:08:09 +00:00
|
|
|
send_location "$1" "${lat}" "${long}"
|
2019-05-12 15:51:52 +00:00
|
|
|
fi
|
|
|
|
sent=y
|
|
|
|
fi
|
2021-01-04 22:08:09 +00:00
|
|
|
if [ "${sent}" != "y" ];then
|
|
|
|
send_text_mode "$1" "${text}"
|
2019-05-12 15:51:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-15 07:47:16 +00:00
|
|
|
# $1 CHAT $2 message starting possibly with html_parse_mode or markdown_parse_mode
|
|
|
|
# not working, fix or remove after 1.0!!
|
2020-12-29 10:02:28 +00:00
|
|
|
send_text_mode() {
|
2019-05-12 15:51:52 +00:00
|
|
|
case "$2" in
|
2020-06-19 16:50:55 +00:00
|
|
|
'html_parse_mode'*)
|
2019-05-12 15:51:52 +00:00
|
|
|
send_html_message "$1" "${2//html_parse_mode}"
|
|
|
|
;;
|
2020-06-19 16:50:55 +00:00
|
|
|
'markdown_parse_mode'*)
|
2019-05-12 15:51:52 +00:00
|
|
|
send_markdown_message "$1" "${2//markdown_parse_mode}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
send_normal_message "$1" "$2"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|