mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 04:45:00 +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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-31-g7694df5
|
||||
#### $$VERSION$$ v0.98-dev-32-g6e3655f
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -756,7 +756,7 @@ process_message() {
|
||||
|
||||
# vunue
|
||||
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[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
||||
@ -772,31 +772,35 @@ process_message() {
|
||||
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
||||
|
||||
# service messages
|
||||
SERVICE=( ); NEWMEMBER=( )
|
||||
SERVICE=( ); NEWMEMBER=( ); LEFTMEMBER=( )
|
||||
if grep -qs -e '\["result",'"${num}"',"message","new_chat_member' <<<"${UPDATE}"; then
|
||||
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
||||
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
||||
NEWMEMBER[FIRST_NAME]="${UPD["result",${num},"message","new_chat_member","first_name"]}"
|
||||
NEWMEMBER[LAST_NAME]="${UPD["result",${num},"message","new_chat_member","last_name"]}"
|
||||
NEWMEMBER[USERNAME]="${UPD["result",${num},"message","new_chat_member","username"]}"
|
||||
NEWMEMBER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","first_name"]}")"
|
||||
NEWMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","last_name"]}")"
|
||||
NEWMEMBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","new_chat_member","username"]}")"
|
||||
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
||||
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
||||
fi
|
||||
if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then
|
||||
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
||||
LEFTMEMBER[ID]="${SERVICE[LEFTMEBER]}"
|
||||
LEFTMEMBER[FIRST_NAME]="${UPD["result",${num},"message","left_chat_member","first_name"]}"
|
||||
LEFTMEMBER[LAST_NAME]="${UPD["result",${num},"message","left_chat_member","last_name"]}"
|
||||
LEFTMEBER[USERNAME]="${UPD["result",${num},"message","left_chat_member","username"]}"
|
||||
LEFTMEMBER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","first_name"]}")"
|
||||
LEFTMEMBER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","last_name"]}")"
|
||||
LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","username"]}")"
|
||||
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
||||
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
||||
fi
|
||||
SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}"
|
||||
SERVICE[NEWPHOTO]="${UPD["result",${num},"message","new_chat_photo"]}"
|
||||
SERVICE[PINNED]="${UPD["result",${num},"message","pinned_message"]}"
|
||||
if grep -qs -e '\["result",'"${num}"',"message","\(new_chat_[tp]\)\|\(pinned_message\)' <<<"${UPDATE}"; then
|
||||
SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result",${num},"message","new_chat_title"]}")"
|
||||
[ -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
|
||||
[[ "${SERVICE[*]}" =~ ^[[:blank:]]+$ ]] || SERVICE[0]="yes"
|
||||
|
||||
[[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes"
|
||||
|
||||
# split message in command and args
|
||||
CMD=( )
|
||||
|
@ -100,10 +100,10 @@ Evertime a Message is received, you can read incoming data using the following v
|
||||
|
||||
### Regular Messages
|
||||
|
||||
* ```${MESSAGE}```: Current message
|
||||
These Variables are always present in regular messages:
|
||||
|
||||
* ```${MESSAGE}```: Current message text
|
||||
* ```${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[ID]}```: User id
|
||||
* ```${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[TYPE]}```: Type
|
||||
* ```${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[ID]}```: ID of message wich was replied to
|
||||
* ```${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[LAST_NAME]}```: Original user's' last name
|
||||
* ```${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[AUDIO]}```: Audio files
|
||||
* ```${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[LATITUDE]}```: Latitude
|
||||
* ```${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}```: set to "yes" when a service message is recived.
|
||||
* ```${SERVICE}```: "yes" if service message is received
|
||||
* ```${SERVICE[NEWMEMBER]```: New user's id
|
||||
* ```${MESSAGE}```: /new_chat_member
|
||||
* ```${NEWMEMBER[ID]```: New user's id
|
||||
* ```${NEWMEMBER[FIRST_NAME]```: New user's first name
|
||||
* ```${NEWMEMBER[LAST_NAME]```: New user's last name
|
||||
* ```${NEWMEMBER[USERNAME]```: New user's username
|
||||
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
||||
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
||||
* ```${LEFTMEMBER[ID]```: New user's id
|
||||
* ```${LEFTMEMBER[FIRST_NAME]```: New user's first name
|
||||
* ```${LEFTMEMBER[LAST_NAME]```: New user's last name
|
||||
* ```${LEFTMEMBER[USERNAME]```: New user's username
|
||||
* ```${LEFTMEMBER[ISBOT]```: New user is a bot
|
||||
* ```${SERVICE[NEWTILE]```: Text of new title
|
||||
* ```${SERVICE[NEWPHOTO]```: New Chat Picture array
|
||||
* ```${MESSAGE}```: /left_chat_member
|
||||
* ```${LEFTMEMBER[ID]```: Left user's id
|
||||
* ```${LEFTMEMBER[FIRST_NAME]```: Left user's first name
|
||||
* ```${LEFTMEMBER[LAST_NAME]```: Left user's last name
|
||||
* ```${LEFTMEMBER[USERNAME]```: Left user's username
|
||||
* ```${LEFTMEMBER[ISBOT]```: Left user is a bot
|
||||
* ```${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
|
||||
* ```${MESSAGE}```: /new_pinned_message
|
||||
|
||||
|
||||
|
||||
### Inline query messages
|
||||
|
||||
|
||||
### Inline queries
|
||||
Evertime a Message is received, you can read incoming data using the following variables:
|
||||
Inline query messages are small, non regular messages used for interaction with the user,
|
||||
they contain the following varibles only:
|
||||
|
||||
* ```${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.
|
||||
@ -261,5 +281,5 @@ send_action "${CHAT[ID]}" "action"
|
||||
#### [Prev Create Bot](1_firstbot.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