mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-29 13:12:36 +00:00
finalize service message processing
This commit is contained in:
parent
6e3655fc2b
commit
18f0ace928
32
bashbot.sh
32
bashbot.sh
@ -11,7 +11,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.98-dev-31-g7694df5
|
#### $$VERSION$$ v0.98-dev-32-g6e3655f
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -756,7 +756,7 @@ process_message() {
|
|||||||
|
|
||||||
# vunue
|
# vunue
|
||||||
VENUE=( )
|
VENUE=( )
|
||||||
if grep -qs -e '\["result",'"${num}"',"message","contact"' <<<"${UPDATE}"; then
|
if grep -qs -e '\["result",'"${num}"',"message","venue"' <<<"${UPDATE}"; then
|
||||||
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
||||||
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||||
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
||||||
@ -772,31 +772,35 @@ process_message() {
|
|||||||
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
||||||
|
|
||||||
# service messages
|
# service messages
|
||||||
SERVICE=( ); NEWMEMBER=( )
|
SERVICE=( ); NEWMEMBER=( ); LEFTMEMBER=( )
|
||||||
if grep -qs -e '\["result",'"${num}"',"message","new_chat_member' <<<"${UPDATE}"; then
|
if grep -qs -e '\["result",'"${num}"',"message","new_chat_member' <<<"${UPDATE}"; then
|
||||||
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
||||||
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
||||||
NEWMEMBER[FIRST_NAME]="${UPD["result",${num},"message","new_chat_member","first_name"]}"
|
NEWMEMBER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","first_name"]}")"
|
||||||
NEWMEMBER[LAST_NAME]="${UPD["result",${num},"message","new_chat_member","last_name"]}"
|
NEWMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","last_name"]}")"
|
||||||
NEWMEMBER[USERNAME]="${UPD["result",${num},"message","new_chat_member","username"]}"
|
NEWMEMBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","username"]}")"
|
||||||
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
||||||
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
||||||
fi
|
fi
|
||||||
if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then
|
if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then
|
||||||
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
||||||
LEFTMEMBER[ID]="${SERVICE[LEFTMEBER]}"
|
LEFTMEMBER[ID]="${SERVICE[LEFTMEBER]}"
|
||||||
LEFTMEMBER[FIRST_NAME]="${UPD["result",${num},"message","left_chat_member","first_name"]}"
|
LEFTMEMBER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","first_name"]}")"
|
||||||
LEFTMEMBER[LAST_NAME]="${UPD["result",${num},"message","left_chat_member","last_name"]}"
|
LEFTMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","last_name"]}")"
|
||||||
LEFTMEBER[USERNAME]="${UPD["result",${num},"message","left_chat_member","username"]}"
|
LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","username"]}")"
|
||||||
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
||||||
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
||||||
fi
|
fi
|
||||||
SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}"
|
if grep -qs -e '\["result",'"${num}"',"message","\(new_chat_[tp]\)\|\(pinned_message\)' <<<"${UPDATE}"; then
|
||||||
SERVICE[NEWPHOTO]="${UPD["result",${num},"message","new_chat_photo"]}"
|
SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result",${num},"message","new_chat_title"]}")"
|
||||||
SERVICE[PINNED]="${UPD["result",${num},"message","pinned_message"]}"
|
[ -n "${SERVICE[NEWTITLE]}" ] && MESSAGE[0]="/new_chat_title ${SERVICE[NEWTITLE]}"
|
||||||
|
SERVICE[NEWPHOTO]="$(get_file "${UPD["result",${num},"message","new_chat_photo",0,"file_id"]}")"
|
||||||
|
[ -n "${SERVICE[NEWPHOTO]}" ] && MESSAGE[0]="/new_chat_photo ${SERVICE[NEWPHOTO]}"
|
||||||
|
SERVICE[PINNED]="$(JsonDecode "${UPD["result",${num},"message","pinned_message"]}")"
|
||||||
|
[ -n "${SERVICE[PINNED]}" ] && MESSAGE[0]="/new_pinned_message ${SERVICE[PINNED]}"
|
||||||
|
fi
|
||||||
# set SSERVICE to yes if a service message was received
|
# set SSERVICE to yes if a service message was received
|
||||||
[[ "${SERVICE[*]}" =~ ^[[:blank:]]+$ ]] || SERVICE[0]="yes"
|
[[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes"
|
||||||
|
|
||||||
|
|
||||||
# split message in command and args
|
# split message in command and args
|
||||||
CMD=( )
|
CMD=( )
|
||||||
|
@ -100,10 +100,10 @@ Evertime a Message is received, you can read incoming data using the following v
|
|||||||
|
|
||||||
### Regular Messages
|
### Regular Messages
|
||||||
|
|
||||||
* ```${MESSAGE}```: Current message
|
These Variables are always present in regular messages:
|
||||||
|
|
||||||
|
* ```${MESSAGE}```: Current message text
|
||||||
* ```${MESSAGE[ID]}```: ID of current message
|
* ```${MESSAGE[ID]}```: ID of current message
|
||||||
* ```$CAPTION```: Captions
|
|
||||||
* ```$REPLYTO```: Original message wich was replied to
|
|
||||||
* ```$USER```: This array contains the First name, last name, username and user id of the sender of the current message.
|
* ```$USER```: This array contains the First name, last name, username and user id of the sender of the current message.
|
||||||
* ```${USER[ID]}```: User id
|
* ```${USER[ID]}```: User id
|
||||||
* ```${USER[FIRST_NAME]}```: User's first name
|
* ```${USER[FIRST_NAME]}```: User's first name
|
||||||
@ -117,6 +117,10 @@ Evertime a Message is received, you can read incoming data using the following v
|
|||||||
* ```${CHAT[TITLE]}```: Title
|
* ```${CHAT[TITLE]}```: Title
|
||||||
* ```${CHAT[TYPE]}```: Type
|
* ```${CHAT[TYPE]}```: Type
|
||||||
* ```${CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]}```: All members are administrators (true if true)
|
* ```${CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]}```: All members are administrators (true if true)
|
||||||
|
|
||||||
|
The following variables are set if the message contains optional parts:
|
||||||
|
|
||||||
|
* ```$REPLYTO```: Original message wich was replied to
|
||||||
* ```$REPLYTO```: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to.
|
* ```$REPLYTO```: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to.
|
||||||
* ```${REPLYTO[ID]}```: ID of message wich was replied to
|
* ```${REPLYTO[ID]}```: ID of message wich was replied to
|
||||||
* ```${REPLYTO[UID]}```: Original user's id
|
* ```${REPLYTO[UID]}```: Original user's id
|
||||||
@ -129,6 +133,7 @@ Evertime a Message is received, you can read incoming data using the following v
|
|||||||
* ```${FORWARD[FIRST_NAME]}```: Original user's first name
|
* ```${FORWARD[FIRST_NAME]}```: Original user's first name
|
||||||
* ```${FORWARD[LAST_NAME]}```: Original user's' last name
|
* ```${FORWARD[LAST_NAME]}```: Original user's' last name
|
||||||
* ```${FORWARD[USERNAME]}```: Original user's username
|
* ```${FORWARD[USERNAME]}```: Original user's username
|
||||||
|
* ```$CAPTION```: Picture, Audio, Video, File Captions
|
||||||
* ```$URLS```: This array contains documents, audio files, voice recordings and stickers as URL.
|
* ```$URLS```: This array contains documents, audio files, voice recordings and stickers as URL.
|
||||||
* ```${URLS[AUDIO]}```: Audio files
|
* ```${URLS[AUDIO]}```: Audio files
|
||||||
* ```${URLS[VIDEO]}```: Videos
|
* ```${URLS[VIDEO]}```: Videos
|
||||||
@ -151,30 +156,45 @@ Evertime a Message is received, you can read incoming data using the following v
|
|||||||
* ```${VENUE[LONGITUDE]}```: Longitude
|
* ```${VENUE[LONGITUDE]}```: Longitude
|
||||||
* ```${VENUE[LATITUDE]}```: Latitude
|
* ```${VENUE[LATITUDE]}```: Latitude
|
||||||
* ```${VENUE[FOURSQUARE]}```: Fouresquare ID
|
* ```${VENUE[FOURSQUARE]}```: Fouresquare ID
|
||||||
|
|
||||||
|
|
||||||
|
### Service Messages
|
||||||
|
|
||||||
|
Service Messages are regular messages not itended for end users, instead they signal special events to the
|
||||||
|
client, e.g. new users.
|
||||||
|
|
||||||
|
If a service message is recieved bashbot sets MESSAGE to the service message type as a command,
|
||||||
|
e.g. if a new user joins a chat MESSAGE is set to "/new_chat_user".
|
||||||
|
|
||||||
* ```$SERVICE```: This array contains info abbout recived service messages.
|
* ```$SERVICE```: This array contains info abbout recived service messages.
|
||||||
* ```${SERVICE}```: set to "yes" when a service message is recived.
|
* ```${SERVICE}```: "yes" if service message is received
|
||||||
* ```${SERVICE[NEWMEMBER]```: New user's id
|
* ```${SERVICE[NEWMEMBER]```: New user's id
|
||||||
|
* ```${MESSAGE}```: /new_chat_member
|
||||||
* ```${NEWMEMBER[ID]```: New user's id
|
* ```${NEWMEMBER[ID]```: New user's id
|
||||||
* ```${NEWMEMBER[FIRST_NAME]```: New user's first name
|
* ```${NEWMEMBER[FIRST_NAME]```: New user's first name
|
||||||
* ```${NEWMEMBER[LAST_NAME]```: New user's last name
|
* ```${NEWMEMBER[LAST_NAME]```: New user's last name
|
||||||
* ```${NEWMEMBER[USERNAME]```: New user's username
|
* ```${NEWMEMBER[USERNAME]```: New user's username
|
||||||
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
||||||
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
||||||
* ```${LEFTMEMBER[ID]```: New user's id
|
* ```${MESSAGE}```: /left_chat_member
|
||||||
* ```${LEFTMEMBER[FIRST_NAME]```: New user's first name
|
* ```${LEFTMEMBER[ID]```: Left user's id
|
||||||
* ```${LEFTMEMBER[LAST_NAME]```: New user's last name
|
* ```${LEFTMEMBER[FIRST_NAME]```: Left user's first name
|
||||||
* ```${LEFTMEMBER[USERNAME]```: New user's username
|
* ```${LEFTMEMBER[LAST_NAME]```: Left user's last name
|
||||||
* ```${LEFTMEMBER[ISBOT]```: New user is a bot
|
* ```${LEFTMEMBER[USERNAME]```: Left user's username
|
||||||
* ```${SERVICE[NEWTILE]```: Text of new title
|
* ```${LEFTMEMBER[ISBOT]```: Left user is a bot
|
||||||
* ```${SERVICE[NEWPHOTO]```: New Chat Picture array
|
* ```${SERVICE[NEWTITLE]```: Text of new title
|
||||||
|
* ```${MESSAGE}```: /new_chat_title
|
||||||
|
* ```${SERVICE[NEWPHOTO]```: New Chat Picture URL
|
||||||
|
* ```${MESSAGE}```: /new_chat_picture
|
||||||
* ```${SERVICE[PINNED]```: Pinned Message structure
|
* ```${SERVICE[PINNED]```: Pinned Message structure
|
||||||
|
* ```${MESSAGE}```: /new_pinned_message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Inline query messages
|
||||||
|
|
||||||
|
Inline query messages are small, non regular messages used for interaction with the user,
|
||||||
### Inline queries
|
they contain the following varibles only:
|
||||||
Evertime a Message is received, you can read incoming data using the following variables:
|
|
||||||
|
|
||||||
* ```${iQUERY}```: Current inline query
|
* ```${iQUERY}```: Current inline query
|
||||||
* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query.
|
* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query.
|
||||||
@ -261,5 +281,5 @@ send_action "${CHAT[ID]}" "action"
|
|||||||
#### [Prev Create Bot](1_firstbot.md)
|
#### [Prev Create Bot](1_firstbot.md)
|
||||||
#### [Next Advanced Usage](3_advanced.md)
|
#### [Next Advanced Usage](3_advanced.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.98-dev-25-g4b18757
|
#### $$VERSION$$ v0.98-dev-32-g6e3655f
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user