2019-04-24 11:34:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# file: modules/inline.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)
|
|
|
|
#
|
2019-05-09 21:34:45 +00:00
|
|
|
#### $$VERSION$$ v0.72-dev-3-g65b32aa
|
2019-04-24 11:34:44 +00:00
|
|
|
|
|
|
|
# source from commands.sh to use the inline functions
|
2019-05-02 10:33:10 +00:00
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
INLINE_QUERY=$URL'/answerInlineQuery'
|
|
|
|
declare -A iQUERY
|
|
|
|
export iQUERY
|
|
|
|
|
2019-05-02 10:33:10 +00:00
|
|
|
process_inline() {
|
2019-05-02 15:28:17 +00:00
|
|
|
local num="${1}"
|
2019-05-02 15:51:37 +00:00
|
|
|
iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")"
|
2019-05-02 15:28:17 +00:00
|
|
|
iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')"
|
|
|
|
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")"
|
|
|
|
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")"
|
|
|
|
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")"
|
2019-05-02 10:33:10 +00:00
|
|
|
}
|
2019-05-02 13:14:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
answer_inline_query() {
|
2019-05-08 12:54:01 +00:00
|
|
|
answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")"
|
2019-05-02 20:20:59 +00:00
|
|
|
}
|
2019-05-08 12:54:01 +00:00
|
|
|
answer_inline_multi() {
|
2019-05-02 20:20:59 +00:00
|
|
|
sendJson "" '"inline_query_id": '"${1}"', "results": ['"${2}"']' "${INLINE_QUERY}"
|
2019-05-02 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 unique ID for answer
|
2019-05-09 12:49:23 +00:00
|
|
|
# $2 type of answer
|
|
|
|
# remaining arguments are the "must have" arguments in the order as in telegram doc
|
|
|
|
# followed by the optional arguments: https://core.telegram.org/bots/api#inlinequeryresult
|
2019-05-08 12:54:01 +00:00
|
|
|
inline_query_compose(){
|
2019-05-02 20:13:06 +00:00
|
|
|
local JSON="{}"
|
|
|
|
local ID="${1}"
|
2019-05-09 14:48:38 +00:00
|
|
|
local fours last
|
|
|
|
# title2Json title caption description markup inlinekeyboard
|
2019-05-02 13:14:18 +00:00
|
|
|
case "${2}" in
|
2019-05-02 20:13:06 +00:00
|
|
|
# user provided media
|
2019-05-09 12:49:23 +00:00
|
|
|
"article"|"message") # article ID title message (markup decription)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"article","id":"'$ID'","message_text":"'$4'"'$(title2Json "$3" "" "$5" "$6")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"photo") # photo ID photoURL (thumbURL title description caption)
|
|
|
|
[ "$4" = "" ] && tumb="$3"
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"photo","id":"'$ID'","photo_url":"'$3'","thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$7" "$6")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"gif") # gif ID photoURL (thumbURL title caption)
|
|
|
|
[ "$4" = "" ] && tumb="$3"
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"gif","id":"'$ID'","gif_url":"'$3'", "thumb_url":"'$4${tumb}'"'$(title2Json "$5" "$6")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"mpeg4_gif") # mpeg4_gif ID mpegURL (thumbURL title caption)
|
|
|
|
[ "$4" != "" ] && tumb='","thumb_url":"'$4'"'
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_url":"'$3'"'${tumb}$(title2Json "$5" "$6")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"video") # video ID videoURL mime thumbURL title (caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"video","id":"'$ID'","video_url":"'$3'","mime_type":"'$4'","thumb_url":"'$5'"'$(title2Json "$6" "$7")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"audio") # audio ID audioURL title (caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"audio","id":"'$ID'","audio_url":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"voice") # voice ID voiceURL title (caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"voice","id":"'$ID'","voice_url":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"document") # document ID title documentURL mimetype (caption description)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"document","id":"'$ID'","document_url":"'$4'","mime_type":"'$5'"'$(title2Json "$3" "$6" "$7")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"location") # location ID lat long title
|
2019-05-02 20:13:06 +00:00
|
|
|
JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"venue") # venue ID lat long title (adress forsquare)
|
|
|
|
[ "$6" = "" ] && addr="$5"
|
|
|
|
[ "$7" != "" ] && fours=',"foursquare_id":"'$7'"'
|
|
|
|
JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"contact") # contact ID phone first (last thumb)
|
|
|
|
[ "$5" != "" ] && last=',"last_name":"'$5'"'
|
|
|
|
[ "$6" != "" ] && tumb='","thumb_url":"'$6'"'
|
|
|
|
JSON='{"type":"contact","id":"'$ID'","phone_number":"'$3'","first_name":"'$4'"'${last}'"}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 14:48:38 +00:00
|
|
|
# title2Json title caption description markup inlinekeyboard
|
2019-05-02 13:14:18 +00:00
|
|
|
# Cached media stored in Telegram server
|
2019-05-09 12:49:23 +00:00
|
|
|
"cached_photo") # photo ID file (title description caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"photo","id":"'$ID'","photo_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"cached_gif") # gif ID file (title caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"gif","id":"'$ID'","gif_file_id":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"cached_mpeg4_gif") # mpeg ID file (title caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"mpeg4_gif","id":"'$ID'","mpeg4_file_id":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-09 12:49:23 +00:00
|
|
|
;;
|
|
|
|
"cached_sticker") # sticker ID file
|
2019-05-02 20:13:06 +00:00
|
|
|
JSON='{"type":"sticker","id":"'$ID'","sticker_file_id":"'$3'"}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"cached_document") # document ID title file (description caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"document","id":"'$ID'","document_file_id":"'$4'"'$(title2Json "$3" "$6" "$5")'}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"cached_video") # video ID file title (description caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"video","id":"'$ID'","video_file_id":"'$3'"'$(title2Json "$4" "$6" "$5")'}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"cached_voice") # voice ID file title (caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"voice","id":"'$ID'","voice_file_id":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
2019-05-09 12:49:23 +00:00
|
|
|
"cached_audio") # audio ID file title (caption)
|
2019-05-09 14:48:38 +00:00
|
|
|
JSON='{"type":"audio","id":"'$ID'","audio_file_id":"'$3'"'$(title2Json "$4" "$5")'}'
|
2019-05-02 13:14:18 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2019-05-02 20:13:06 +00:00
|
|
|
echo "${JSON}"
|
2019-05-02 13:14:18 +00:00
|
|
|
}
|
|
|
|
|