From 56a45aa883cb5040131fb743e44795bde16c9b59 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Apr 2019 19:00:17 +0200 Subject: [PATCH] parse VCARD and VENUE from message --- bashbot.sh | 18 +++++++++++++----- doc/2_usage.md | 11 +++++++++-- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_message-test.sh | 4 ++-- .../d-process_message-test.result | 6 ++++++ test/d-user_is-test.sh | 2 +- 12 files changed, 38 insertions(+), 17 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 2e2a0ed..076ba95 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,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-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # # Exit Codes: # - 0 sucess (hopefully) @@ -157,8 +157,8 @@ UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' unset USER -declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO - +declare -A USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE +export USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE send_message() { @@ -600,10 +600,18 @@ process_message() { URLS[VOICE]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","voice","file_id"' <"$TMP")")" # Contact - CONTACT[NUMBER]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")")" + CONTACT[USER_ID]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","user_id"' <"$TMP")")" CONTACT[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","first_name"' <"$TMP")")" CONTACT[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","last_name"' <"$TMP")")" - CONTACT[USER_ID]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","user_id"' <"$TMP")")" + CONTACT[NUMBER]="$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")" + CONTACT[VCARD]="$(JsonGetString '"result",'"${num}"',"message","contact","vcard"' <"$TMP")" + + # vunue + VENUE[TITLE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","title"' <"$TMP")")" + VENUE[ADDRESS]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","address"' <"$TMP")")" + VENUE[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","longitude"' <"$TMP")" + VENUE[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","latitude"' <"$TMP")" + VENUE[FOURSQUARE]="$(JsonGetString '"result",'"${num}"',"message","venue","foursquare_id"' <"$TMP")" # Caption CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")" diff --git a/doc/2_usage.md b/doc/2_usage.md index af1d19f..ee5a70d 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -74,13 +74,20 @@ Evertime a Message is recieved, you can read incoming data using the following v * ```${URLS[STICKER]}```: Stickers * ```${URLS[DOCUMENT]}```: Any other file * ```$CONTACT```: This array contains info about contacts sent in a chat. + * ```${CONTACT[ID]}```: User id * ```${CONTACT[NUMBER]}```: Phone number * ```${CONTACT[FIRST_NAME]}```: First name * ```${CONTACT[LAST_NAME]}```: Last name - * ```${CONTACT[ID]}```: User id + * ```${CONTACT[VCARD]}```: User's complete Vcard * ```$LOCATION```: This array contains info about locations sent in a chat. * ```${LOCATION[LONGITUDE]}```: Longitude * ```${LOCATION[LATITUDE]}```: Latitude +* ```$VENUE```: This array contains info about venue (a place) sent in a chat. + * ```${VENUE[TITLE]}```: Name of the place + * ```${VENUE[ADDRESS]}```: Address of the place + * ```${VENUE[LONGITUDE]}```: Longitude + * ```${VENUE[LATITUDE]}```: Latitude + * ```${VENUE[FOURSQUARE]}```: Fouresquare ID ## Usage of bashbot functions @@ -159,5 +166,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 1c31425..1194755 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 946f329..bf360bb 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index c6eea8b..f88147e 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev2-11-g8549727 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 8ad120f..e1df301 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 35ca2cf..777e936 100755 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 5fcb204..7407863 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-10-gfa9e879 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 0ea4597..3a0b03e 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 2f5a2ae..d8bfd18 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -32,7 +32,7 @@ do { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; # output processed input - print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}" + print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}" diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 echo "${SUCCESS}" done diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test.result index 116cf0d..b4cf952 100644 --- a/test/d-process_message-test/d-process_message-test.result +++ b/test/d-process_message-test/d-process_message-test.result @@ -30,8 +30,14 @@ CONTACT: FIRST_NAME ADAC CONTACT: LAST_NAME Pannenhilfe CONTACT: NUMBER 222222 CONTACT: USER_ID +CONTACT: VCARD BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD CAPTION: 0 LOCATION: LATITUDE 49.631824 LOCATION: LONGITUDE 8.377072 MESSAGE: 0 😂😝👌☺❤😕😈#⃣🌏🎉🙊🙉☕🚀✈🚂💯✔〽🔚 MESSAGE: ID 6541 +VENUE: ADDRESS Am Rhein 1 +VENUE: FOURSQUARE 4c4321afce54e21eee980d1a +VENUE: LATITUDE 49.631824 +VENUE: LONGITUDE 8.377072 +VENUE: TITLE Kolb's Biergarten diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index e0b6b9b..685be28 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-12-gaa93839 +#### $$VERSION$$ v0.70-dev2-13-gca73be8 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh