mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 08:47:34 +00:00
fix inline query extraction and response
This commit is contained in:
parent
cbdfc7c945
commit
6afa177e4a
29
commands.sh
29
commands.sh
@ -5,11 +5,10 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
# shellcheck disable=SC2128
|
|
||||||
|
|
||||||
# adjust your language setting here, e.g.when run from other user or cron.
|
# 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
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
@ -49,11 +48,12 @@ else
|
|||||||
# defaults to no inline and nonsense home dir
|
# defaults to no inline and nonsense home dir
|
||||||
INLINE="0"
|
INLINE="0"
|
||||||
FILE_REGEX='/home/user/allowed/.*'
|
FILE_REGEX='/home/user/allowed/.*'
|
||||||
fi
|
|
||||||
|
|
||||||
# load modules needed for bashbot.sh also
|
# load modules needed for bashbot.sh also
|
||||||
# shellcheck source=./modules/background.sh
|
# shellcheck source=./modules/background.sh
|
||||||
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
|
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# load mycommands
|
# load mycommands
|
||||||
# shellcheck source=./commands.sh
|
# shellcheck source=./commands.sh
|
||||||
@ -72,28 +72,33 @@ if [ "${1}" != "source" ];then
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
||||||
if _is_function process_inline; then
|
if _is_function process_inline; then
|
||||||
#######################
|
#######################
|
||||||
# Inline query examples
|
# Inline query examples
|
||||||
|
# shellcheck disable=SC2128
|
||||||
case "${iQUERY}" in
|
case "${iQUERY}" in
|
||||||
"photo")
|
"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")
|
"sticker")
|
||||||
_answer_inline "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
|
answer_inline_query "${iQUERY[ID]}" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
|
||||||
;;
|
;;
|
||||||
"gif")
|
"gif")
|
||||||
_answer_inline "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
|
answer_inline_query "${iQUERY[ID]}" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
|
||||||
;;
|
;;
|
||||||
"web")
|
"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
|
# GLOBAL commands start here, edit messages only
|
||||||
'/info'*)
|
'info')
|
||||||
_answer_inline "article" "Info" "${bashbot_info}" "markdown"
|
answer_inline_query "${iQUERY[ID]}" "article" "${bashbot_info}"
|
||||||
;;
|
;;
|
||||||
*) # forward iinline query to optional dispatcher
|
*) # forward iinline query to optional dispatcher
|
||||||
_is_function myinlines && myinlines
|
_is_function myinlines && myinlines
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# 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
|
# source from commands.sh to use the inline functions
|
||||||
|
|
||||||
@ -24,15 +24,15 @@ process_inline() {
|
|||||||
|
|
||||||
|
|
||||||
answer_inline_query() {
|
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}"
|
sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 unique ID for answer
|
# $1 unique ID for answer
|
||||||
# remaining arguments are in the order as shown in telegram doc: https://core.telegram.org/bots/api#inlinequeryresult
|
# 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 JSON="{}"
|
||||||
local ID="${1}"
|
local ID="${1}"
|
||||||
case "${2}" in
|
case "${2}" in
|
||||||
@ -42,16 +42,19 @@ inline_query_result(){
|
|||||||
JSON='{"type":"article","id":"'$ID'","title":"'$3'","message_text":"'$4'"'"${parse}"'}'
|
JSON='{"type":"article","id":"'$ID'","title":"'$3'","message_text":"'$4'"'"${parse}"'}'
|
||||||
;;
|
;;
|
||||||
"photo")
|
"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")
|
"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")
|
"mpeg4_gif")
|
||||||
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"}'
|
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"}'
|
||||||
;;
|
;;
|
||||||
"video")
|
"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")
|
"audio")
|
||||||
JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'","title":"'$4'"}'
|
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'"}'
|
JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}'
|
||||||
;;
|
;;
|
||||||
"venue")
|
"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")
|
"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 media stored in Telegram server
|
||||||
"cached_photo")
|
"cached_photo")
|
||||||
|
Loading…
Reference in New Issue
Block a user