fix inline query extraction and response

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-08 14:54:01 +02:00
parent cbdfc7c945
commit 6afa177e4a
2 changed files with 30 additions and 21 deletions

View File

@ -5,11 +5,10 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-7-g66c390e
#### $$VERSION$$ v0.70-10-gcbdfc7c
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
# shellcheck disable=SC2128
# adjust your language setting here, e.g.when run from other user or cron.
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
@ -49,11 +48,12 @@ else
# defaults to no inline and nonsense home dir
INLINE="0"
FILE_REGEX='/home/user/allowed/.*'
fi
# load modules needed for bashbot.sh also
# shellcheck source=./modules/background.sh
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
# load modules needed for bashbot.sh also
# shellcheck source=./modules/background.sh
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
fi
# load mycommands
# shellcheck source=./commands.sh
@ -72,28 +72,33 @@ if [ "${1}" != "source" ];then
fi
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
if _is_function process_inline; then
#######################
# Inline query examples
# shellcheck disable=SC2128
case "${iQUERY}" in
"photo")
_answer_inline "photo" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg"
answer_inline_multi "${iQUERY[ID]}" "
$(inline_query_compose "$RANDOM" "photo" "https://avatars0.githubusercontent.com/u/13046303"),
$(inline_query_compose "$RANDOM" "photo" "https://avatars1.githubusercontent.com/u/4593242")
"
;;
"sticker")
_answer_inline "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
answer_inline_query "${iQUERY[ID]}" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
;;
"gif")
_answer_inline "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
answer_inline_query "${iQUERY[ID]}" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
;;
"web")
_answer_inline "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
answer_inline_query "${iQUERY[ID]}" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
;;
################################################
# GLOBAL commands start here, edit messages only
'/info'*)
_answer_inline "article" "Info" "${bashbot_info}" "markdown"
'info')
answer_inline_query "${iQUERY[ID]}" "article" "${bashbot_info}"
;;
*) # forward iinline query to optional dispatcher
_is_function myinlines && myinlines

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-8-g0582a2a
#### $$VERSION$$ v0.70-10-gcbdfc7c
# source from commands.sh to use the inline functions
@ -24,15 +24,15 @@ process_inline() {
answer_inline_query() {
answer_inline "${1}" "$(shift; inline_query_result "$RANDOM" "$@")"
answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")"
}
answer_inline() {
answer_inline_multi() {
sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}"
}
# $1 unique ID for answer
# remaining arguments are in the order as shown in telegram doc: https://core.telegram.org/bots/api#inlinequeryresult
inline_query_result(){
inline_query_compose(){
local JSON="{}"
local ID="${1}"
case "${2}" in
@ -42,16 +42,19 @@ inline_query_result(){
JSON='{"type":"article","id":"'$ID'","title":"'$3'","message_text":"'$4'"'"${parse}"'}'
;;
"photo")
JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4'"}'
[ "$4" = "" ] && local tumb="$3"
JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"}'
;;
"gif")
JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4'"}'
[ "$4" = "" ] && local tumb="$3"
JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"}'
;;
"mpeg4_gif")
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"}'
;;
"video")
JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'","title":"'$6'"}'
[ "$5" = "" ] && local tumb="$3"
JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5${tumb}'","title":"'$6'"}'
;;
"audio")
JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'","title":"'$4'"}'
@ -66,10 +69,11 @@ inline_query_result(){
JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}'
;;
"venue")
JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6'"}'
[ "$6" = "" ] && local addr="$5"
JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"}'
;;
"contact")
JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'"}'
JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'","last_name":"'$5'"}'
;;
# Cached media stored in Telegram server
"cached_photo")